[thelist] php and result sets
johnpeace
webshot at members.evolt.org
Wed Mar 27 12:50:01 CST 2002
At this URL http://www.dianalehr.com/index2.php
I use the following PHP to get a result set from my database and create
arrays of image tags, one array for each category of image.
<code>
<?php
$query = "SELECT art_ID, title, path, category FROM artworks";
//get the array
$rs = safe_query($query);
echo ("<meta name=\"Keywords\" content=\"");
$keywords = "Diana Lehr, Maui Art, Maui Artist, Olinda Road, Makawao, ";
// thumbnail path
$thumbnail_path = "images/thumbnails/";
while ($row = mysql_fetch_array($rs))
{
$keywords .= $row["title"] . ", ";
//create arrays for the paintings in each category
if (substr($row["category"], 0, 1) == "p")
{
//make an array of image tags for this category
$id = $row["art_ID"];
$tn = $thumbnail_path . $row["path"];
$img_size = GetImageSize ($tn);
$img_size = $img_size[3];
$alt = $row["title"];
$img_tag = "<img src=\"$tn\" $img_size alt=\"$alt\">";
$js_link = "<a href=\"detail.php?id=".$id."\">";
$pastel_tn[] = $js_link . $img_tag . "</a>";
}
else if (substr($row["category"], 0, 1) == "o")
{
//make an array of image tags for this category
$id = $row["art_ID"];
$tn = $thumbnail_path . $row["path"];
$img_size = GetImageSize ($tn);
$img_size = $img_size[3];
$alt = $row["title"];
$img_tag = "<img src=\"$tn\" $img_size alt=\"$alt\">";
$js_link = "<a href=\"detail.php?id=".$id."\">";
$oil_tn[] = $js_link . $img_tag . "</a>";
}
else if (substr($row["category"], 0, 1) == "w")
{
//make an array of image tags for this category
$id = $row["art_ID"];
$tn = $thumbnail_path . $row["path"];
$img_size = GetImageSize ($tn);
$img_size = $img_size[3];
$alt = $row["title"];
$img_tag = "<img src=\"$tn\" $img_size alt=\"$alt\">";
$js_link = "<a href=\"detail.php?id=".$id."\">";
$watercolor_tn[] = $js_link . $img_tag . "</a>";
}
unset($id);
unset($tn);
unset($img_size);
unset($alt);
unset($img_tag);
unset($js_link);
}
$keywords = substr_replace($keywords, '', -2);
echo ($keywords);
echo("\">\n");
?>
</code>
So, aside from the fact that I could be doing my array assignments in a
function, why does this not work the way it is supposed to? If you look at
http:///www.dianalehr.com/index.php you can see what it is supposed to look
like. This page generates its thumbnails with a separate query for each
category of painting, in revisiting the site after about a year, I decided
to clean it up a little bit. I think there's something screwy with my array
assignments, but I cant' figure it out.
anyone?
thanks,
John
More information about the thelist
mailing list