[thelist] php and result sets

Hans Zaunere zaunere at yahoo.com
Wed Mar 27 15:42:00 CST 2002


Are you sure you're getting the data you expect?
You're array building is all exactly the same, so it
must not be there but use a function to ensure theres
no typo.

Also think about using:

switch( $row["category"]{0} ) {
   case 'p':
   case 'P':
      // function call
      break;

   case 'o':
   case 'O':
      // function call
      break;

   case 'w':
   case 'W':
      // function call
      break;

   default:
      // something else happened
}

This is much better than that if-else substr()
business and will let you debug easier.

Hans Z.
New York PHP
http://nyphp.org







--- johnpeace <webshot at members.evolt.org> wrote:
> 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
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !


__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/



More information about the thelist mailing list