Supposed to output three diff items, get 2 of the last item but no others

From: Date: Wed, 07 Nov 2001 16:31:49 +0000
Subject: Supposed to output three diff items, get 2 of the last item but no others
Groups: php.general 
Request: Send a blank email to php-general+get-73750@lists.php.net to get a copy of this message
Yes I write long subjects. Yes I'm about to show you some code. :) Can someone please give me a hint or point out where I am messing up. I usually code in JSP, which has some similarly, but pulling items from the database should be giving me 3 categories and two images a piece, but its giving me the last category and giving it to me twice. Any help would be appreaciated :) <? /* declare connection variables */ $DBhost = "localhost"; $DBuser = "root"; $DBpass = "px18900"; $DBName = "copeland"; $id; /*connect */ mysql_connect($DBhost,$DBuser,$DBpass) or die ("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $sql = "SELECT * FROM categories WHERE parent_id = 0 ORDER BY sort_order ASC"; $result = mysql_query($sql); if ($result) { $nrows = mysql_num_rows($result); } while ($category = mysql_fetch_array($result)) { $cat_picture = $category["cat_image"]; $cat_txt_image = $category["cat_txt_image"]; $cat_atl_tag = $category["cat_name"]; //$cat_img_path = "images/product/"; $cat_image_p = "<img src=\"images/product/".$cat_picture."\" border=\"0\" alt=\"".$cat_atl_tag."\">"; $cat_image_t = "<img src=\"images/product/".$cat_txt_image."\" border=\"0\" alt=\"".$cat_atl_tag."\">"; if ($category[single] == "1") { /* Go down a level */ $catid = $category["id"]; $sqlb = "SELECT collection_id FROM collections WHERE parent_id = $catid"; $resultb = mysql_query($sqlb); $collection = mysql_fetch_array($resultb); $cat_link = "<a href=test3.php?id=".$collection["collection_id"].">"; } else { $cat_link = "<a href=test2.php?id=".$category["id"].">"; } for ($i = 0; $i < $nrows; $i++) { $cat_output = "<center>"; $cat_output .= "".$cat_link."".$cat_image_t."".$cat_image_p."<br><br>"; if ( ($i % 2) == 0) { $cat_output .= "".$cat_link."".$cat_image_p."".$cat_image_t."<br><br>"; } } } $cat_output .= "</center>"; $cat_breadcrumb = "<font face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">products :</font><br><br>"; ?> <html> <head> <title>Test Template</title> </head> <body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" rightmargin="0" bottommargin="0"> <? print $cat_breadcrumb; print $cat_output; ?> </body> </html> ===== Dan McCullough ------------------------------------------------------------------- "Theres no such thing as a problem unless the servers are on fire!" h: 603.444.9808 w: McCullough Family w: At Work __________________________________________________ Do You Yahoo!? Find a job, post your resume. http://careers.yahoo.com

« previous php.general (#73750) next »