RE: [PHP] Populating HTML List boxes From DB

From: Date: Tue, 17 Apr 2001 02:05:51 +0000
Subject: RE: [PHP] Populating HTML List boxes From DB
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-48863@lists.php.net to get a copy of this message
Thanks Every one it now works like a charm (o: -----Original Message----- From: Jason Murray [mailto:Jason.Murray@melbourneit.com.au] Sent: Tuesday, April 17, 2001 11:55 AM To: 'Peter Houchin'; Jason Murray; Php-General@Lists. Php. Net Subject: RE: [PHP] Populating HTML List boxes From DB > <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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#48863) next »