RE: [PHP] Populating HTML List boxes From DB

From: Date: Tue, 17 Apr 2001 01:55:10 +0000
Subject: RE: [PHP] Populating HTML List boxes From DB
Groups: php.general 
Request: Send a blank email to php-general+get-48860@lists.php.net to get a copy of this message
> <select name="device"> > <?php > $query ="SELECT DISTINCT device FROM 3backup ORDER BY device"; > $rs =mysql_query($query); $rs is now the result set for your SQL. > $device = mysql_result($rs, 'device'); This is wrong. Check the manual page for how you use mysql_result. http://www.php.net/mysql-result > while($row = mysql_fetch_object($rs)){ > echo '<option value="'; > echo $device; > echo '">'; > echo $device; > echo '</option>\n'; > } This is odd. Having pulled out the device (or tried to), you're now creating an object and then not using it. Try this: <select name="device"> <?php $query = "SELECT DISTINCT device FROM 3backup ORDER BY device"; $rs = mysql_query($query); while($row = mysql_fetch_row($rs)) { echo '<option value="'.$row[device].'">'.$row[device].'</option>\n'; } ?> </select> Now, in order for this to produce more than one option in the dropdown box, you have to be sure that your SELECT DISTINCT does in fact return more than one row. Jason

« previous php.general (#48860) next »