I am tring to display a thumbnail without creating a a new image. I have a script that I reduce the image size to the size I need but I am having trouble displaying that image in a do while loop while pulling other info from a database. I want to display all records in the database with a auto generated thumbnail for each record. The image name is stored in a field in the database. The original is stored in a folder. Here is the script:
Any help would be appreciated
<?php
header('Content-type: image/jpeg');
$connection = mysql_connect ("localhost", "$username", "$password");
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
$query = "SELECT * FROM dir ORDER BY hiredate DESC";
$result = mysql_db_query ($database, $query)or die;
("Query failed");
$num = mysql_num_rows($result);
if ($num == "0"){}
$limit=4;
if (empty($offset)) {$offset=0;}
$query = "SELECT * FROM dir ORDER BY hiredate DESC LIMIT $offset,$limit";
$result = mysql_db_query ($database, $query)or die;
("Query failed");
$data=mysql_fetch_array($result);
echo"
<center><table width=750 height=400 cellpadding=10 border=0>
<tr><td align=left valign=top bgcolor=black>
<br><br>
</td></tr>
<tr><td align=center valign=top>
<font face=arial size=4>
Employee Directory
</font><br><br>
<a href='emp_directory.php'>New Employees</a><br><br>
";
echo "<center><table width=500 border=0 cellpadding=20 cellspacing=0>";
do {
if ($imgcnt = 0) {print "<tr>";}
do{
$data[2]=stripslashes($data[2]);
$ed=$data[10];
$td=date("z");
$ed3=$data[10];
$td3=date("Y-m-d");
$ed2=explode("-", $ed3);
$td2=explode("-", $td3);
if($ed2[0] < $td2[0]){$new="";
}else{
$caldate=date('z', strtotime("-1 day", strtotime("$ed")));
$td1=($td-$caldate-1);
if($td1 <= "30"){$new="<img src=image/new2.gif>";}else{$new="";}
}
echo "
<center><td height=100 align=center valign=top>
<a href='preview.php?empname=$data[0]' border=0>
//This is where I need the Image
</a></td>
<td width=400 height=100 align=left valign=top><font face=Arial size=2>
<b>Employee Name:</b> $data[0]   $new<br>
<b>Title:</b> $data[1]<br>
<b>Location:</b> $data[2]<br>
<b>Email Address:</b> <a href='mailto:$data[3]'>$data[3]</a><br>
<b>Phone:</b> $data[4]<br>
<b>Mobile:</b> $data[5]<br>
<b>Skype:</b> $data[6]<br>
<b>MSN:</b> $data[7]<br>
<b>Hire Date:</b> $data[10]<br>
</font></td></center>
";
$imgcnt = $imgcnt + 1;
} while ($imgcnt != 1 AND $data=mysql_fetch_array($result));
if ($imgcnt = 1)
{print "</tr>";
$imgcnt = 0;}
}while ($data=mysql_fetch_array($result));
print " </tr></table><br></center>";
print "<center><table width=400><tr><td align=left width=100>";
if ($offset == 0) { } else {$prevoffset=$offset-$limit;
echo "
<center><a href='$PHP_SELF?offset=$prevoffset'>
<font face=Arial color=blue size=4> Prev</font></a></center>";
}
print "</td><td width=200>";
$pages=intval ($num/$limit);
if ($num%$limit) {$pages++;}
for ($i=1;$i<=$pages;$i++) {$newoffset=$limit* ($i-1);
echo "<a href='$PHP_SELF?offset=$newoffset'>
<font face=Arial color=blue size=3> $i </font></a>";
}
print "</td><td width=100 align=center>";
if (!((($offset+4)/$limit) ==$pages) && $pages != 1) {$newoffset=$offset+$limit;
echo "
<center><a href='$PHP_SELF?offset=$newoffset'>
<font face=Arial color=blue size=4>Next</font></a></center>";
}
print "</td</tr></table></center>";
imagejpeg($thumb);
print"</td></tr></table></center>";
?>
Here is the resize script:
function resize(){
$imgfile="images/nobodypic.jpg";
$percent="0.5";
list($width, $height) = getimagesize($imgfile);
$newwidth = $width $percent;
$newheight = $height $percent;
$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = imagecreatefromjpeg($imgfile);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb);
}
echo resize();