Execute and count the results:
// execute the query
$result = mysql_query($query);
// get the number of results
$num_rows = mysql_num_rows($result);
The results
We start with a basic html-page. We also include a JavaScript function (borrowed from www.vpro.nl) to display the popup with a larger version of the image.
?><html>
<script language="javascript">
/* source: www.vpro.nl */
function bigImage(name) {
if (navigator.appName=="Netscape") {
var imagewindow = window.open('bigimage.php?f='+name,'imagewindow'+name,
'resizable=yes,scrollbars=no,status=1,innerWidth=450,innerHeight=402');
}
else {
var imagewindow = window.open('bigimage.php?f='+name,'imagewindow'+name,
'resizable=yes,scrollbars=yes,status=1,width=450,height=402');
}
}
</script>
<body>
<h1>Search Results</h1>
<table><?php
Per image, we display one table row. We add a popup link to bigimage.php, a script that displays a larger version of the image. We just link to it for now, we will write bigimage.php in the next step. The img_tag function is used to generate the img tag.
// one row for each result
for ($i=0; $i<$num_rows; $i++) {
// fetch row
$img_info = mysql_fetch_array($result);
// start table row
echo '<tr><td><a href="bigimage.php?f='.$img_info["img_file"].'" '.
'target="_new" onclick="bigImage('."'".$img_info["img_file"]."')".
'; return false;">';
// generate the image tag
echo img_tag($img_info["img_file"], array("x"=>"250"));
// echo image information
echo "</a></td><td><b>".$img_info["img_title"]."</b><br>".
$img_info["img_descr"]."<hr><b>Alt:</b> ".$img_info["img_alt"].
"<br><b>Pixels:</b> ".$img_info["img_width"]."x".
$img_info["img_height"]."<br><b>Bytes:</b> ".
$img_info["img_bytes"]."<br><b>Type:</b> ".
$img_info["img_type"]."</td></tr>\n";
}
Now just close the table, body and html tags and your search script is finished.
Bigimage.php
As said, this script isn't very complicated. It uses the img_tag function to display a larger version of the image. That image links to the full-size version of the image. Save the code as bigimage.php and you're ready.
<html>
<body>
<?php
include("imgtag.php");
echo '<a href="img.php?f('.$HTTP_GET_VARS["f"].')">';
echo img_tag($HTTP_GET_VARS["f"], array("x"=>"400"));
echo '</a>';
?>
</body>
</html>