Re: Display Mysql Result in drop down list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <1072155150.3fe7ca0ec4015@xxxxxxxxxxxxxxxxxxxxx>, 
irinchiang@xxxxxxxxxxxxxxxxx says...
> 
> Hi all, 
> 
> Right now I'm trying to retrieve one of the column "tutor_name" and display al 
> the tutor's name in a drop down list. The problem now is, the drop down list 
> only manage to display 1 record from that row instead of all tutor's name 
> under "tutor_name" column...wonder where the problem lies??
> Hope to get some help soon.
> Below is a snip of the code: 
> Drop me a msg if anyone needs the entire code.
> 
> 
> 
> <SELECT NAME="tutor_name" class="textarea">
> <?
> 
> 
> $sql = mysql_query("SELECT DISTINCT tutor_name FROM tutor ");
> if ($row = mysql_fetch_array($sql))

replace the above with
while ($row = mysql_fetch_array($sql))

If will be true, but will only produce one result. You want to iterate 
through all results, which is why you use while. It will return as many 
results as are available.

> {
>  print "<OPTION VALUE=\"$tutor_name\" SELECTED>" .$row
> ["tutor_name"]. "</option>";
>  }
>  $result = $db->query($sql);
> 
> ?>
> </select>
> 
> 
> Thanks in advance =)
> 
> Irin.
> 

-- 
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux