Image in For loop

From: Date: Wed, 13 Sep 2000 23:22:53 +0000
Subject: Image in For loop
Groups: php.general 
Request: Send a blank email to php-general+get-16662@lists.php.net to get a copy of this message
Hi people, I have a PHP related question. I currently have a site that I am constructing using php and mysql. The page is going great so far. However I have a request from the client that he has decided to throw in after I have constructed my initial mysql queries. The situation I have currently is this: My query selects data from the database and displays it in this manner Category name (image) Category data in a table category name (image Category data in a table etc etc My client now wants the data to be displayed as such Category name (image) Category data in a table An image contaning a link to an anchor tag at the top of the page. For the life of me I cannot get this to work, all I seem to be getting is Category name (image) Category data in a table (single line of data) Image (anchor link) Category data (second line of data) Image (anchor link) etc etc The code that I am using for the initial layout is as below. How can I modify this code to achieve the clients requested layout? Any help on this would be greatly appreciated. <? $catname = ""; $sql = "select category,id,description,extax,price from dealers where page = 'accessories' order by category"; $dbh = @mysql_connect($dbhost,$dbuser,$dbpass); $results = mysql_db_query($db,$sql,$dbh); for($i = 0; $i < mysql_num_rows($results); $i++) { $array[$i] = mysql_fetch_array($results); } mysql_close($dbh); for ($i = 0; $i < count($array); $i++) { if ($array[$i]["category"] != $catname) { $catname = $array[$i]["category"]; echo "<tr><td colspan='4'><a name='".$catname."'></a><br><img src='images/".$catname.".jpg' width='443' height='32'></td></tr>"; } echo "<tr><td width='25'></td><td width='308'><p><a href=javascript:order_now(&quot;".$array[$i]["id"]."&quot;)><img src='../nav/lil_cart.gif' border='0'>".$array[$i]["description"]."</a></p></td><td width='55' align='right'><p>".$array[$i]["extax"]."</p></td><td width='55' align='right'><p>".$array[$i]["price"]."</p></td></tr>\n"; } ?> thankyou for any help -Shannon

« previous php.general (#16662) next »