Forum Moderators: coopster

Message Too Old, No Replies

Limiting options in DD box

when the same exists many times in same col

         

henry0

9:18 pm on Apr 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I cannot find a way to do that
I have a table populated with a few col, among those is “city”

Then I built a DD box to select a city name
But it could be many times the same city name in that col
So for ex: if I have in that table 3 times AAA
How could I only grab a unique city name and not echo it three times in the DD box

if I write some useless procedure I will probably get it
but it got to be a simple way

of course LIMIT 1 is not an option (we need all cities)

<<<<<<<<<<<
print <<< FORM
<p><form action="search.php" method="post">
<label for="wide_search">Select a CITY to review aaaa.</label></p>
FORM;

$conn=db_connect();

$query = "select city from zxzxzx where state ='$state' ORDER by city ASC";
$result= mysql_query($query);
$num=mysql_num_rows($result);
$i=0;
echo '<select name="wide_search">';
while ($i <$num)
{
echo '<option>';
$wide_search=mysql_result($result,$i,"city");
echo"$wide_search";
$i++;
}

print <<< CITY
<p>
<input type="submit" value="Select a City" /></form>
</p>
CITY;

>>>>>>>>>>>>>>>

eelixduppy

9:26 pm on Apr 5, 2007 (gmt 0)



If I understand your problem correctly I believe DISTINCT [dev.mysql.com] will do it for you:

$query = "SELECT DISTINCT `city` FROM zxzxzx WHERE `state` = '".mysql_real_escape_string($state)."' ORDER BY `city` ASC";

henry0

9:33 pm on Apr 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Never had a need for it before
BUT THIS IS THE ONE!
Smilling all the way to my query :)
thanks

eelixduppy

9:37 pm on Apr 5, 2007 (gmt 0)



hehe

Glad it turned out to be an easy fix! ;)