php/mySQL help

From: Date: Wed, 07 Feb 2001 21:00:29 +0000
Subject: php/mySQL help
Groups: php.db 
Request: Send a blank email to php-db+get-6453@lists.php.net to get a copy of this message
Hi everyone..been away and off the list for awhile.i am back to work and need some help. I am not sure if I am having a problem with my PHP or mySQL. I have a table called "Restaurant" with a field called "Cuisine". There are 5 records in this table. When I run my code, it only returns one cuisine when there are 5. I am trying to get all the Cuisines in the array called CuisineMenuArray with no duplicates so I can generate a drop-down menu of cuisines "on the fly". Any help would be greatly appreciated! Thanx. Here is the code: <?php $db=mysql_connect("localhost", "*******", "********"); mysql_select_db("quickcit", $db) OR DIE ("died at connect"); $query = "SELECT Restaurant.Cuisine "; $query .= "FROM Restaurant "; $query .= "ORDER BY Restaurant.Cuisine ASC "; $mysql_result=mysql_query($query, $db) OR DIE ("died at query"); if(mysql_num_rows($mysql_result)) { $h = 0; $i = 1; while ($row=mysql_fetch_array($mysql_result)); { if ($i == 1) { //this only happens once since $i has the value 1 here only. $CuisineMenuArray[0] = $row[0]; } //this checks the next instance in $row against the previous instance in $CuisineMenuArray. If they are not the same, it adds what is in $row to thenext position in $CuisineMenuArray. If theyare the same it just skips to the next instance in $row and checks it against the last instance in $CuisineMenuArray again. if ($row[$i] != $CuisineMenuArray[$h]) { $CuisineMenuArray[$h+1] = $row[$i]; echo "$CuisineMenuArray[$h]"; echo "$row[$i]"; $h = ($h + 1); $i = ($i + 1); } else { $i = ($i + 1); } } } ?> Scott Stinsman Academic Coordinator General Internal Medicine 1215 Blockley Hall 423 Guardian Drive Philadelphia, PA 19104-6021 (phone) 215-662-7623 (fax) 215-349-5091 (email) scott.stinsman@uphs.upenn.edu

« previous php.db (#6453) next »