Re: php/mySQL help
| From: | php3 at developersdesk dot com | Date: | Thu, 08 Feb 2001 05:43:27 +0000 |
| Subject: | Re: php/mySQL help | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-6465@lists.php.net to get a copy of this message | ||
Addressed to: "Stinsman, Scott" <scott.stinsman@uphs.upenn.edu>
php-db@lists.php.net
** Reply to note from "Stinsman, Scott" <scott.stinsman@uphs.upenn.edu> Wed, 7 Feb
2001 16:00:29 -0500
>
> 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");
>
Try changing you Query to:
SELECT DISTINCT Cuisine
FROM Restaurant
ORDER BY Cousine
Then rely on the DISTINCT to insure you only get one copy of the value
in your array.
while( list( $Couisine ) = mysql_fetch_row( $Result )) {
$CouisineList[] = $Couisine;
}
And you are done...
Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com