Re: populating dropdown list problems

From: Date: Tue, 10 Apr 2001 01:11:20 +0000
Subject: Re: populating dropdown list problems
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47913@lists.php.net to get a copy of this message
On Tue, 10 Apr 2001 04:37, Jason Dulberg wrote: > I would like to populate a dropdown list from a particular field of a > bunch of records. > Here's what I have so far on the modify page but it doesn't list stuff > from the database, all it prints is the number 1 which isn't in any of > the records. > > One version of this will be on an add page and another will be on a > modify page which has the current field selected. For the add script, > I'd just lose all the selected stuff that's on there now. > > print "<select name=\"owner\">"; > $result = mysql_query("SELECT owner,agent FROM homes;"); > while($a_row = mysql_fetch_array($result)) > { > printf('<option name="owner" > > value="'.$a_row[owner].'">'.$a_row[owner].'</option>', > $a_row[owner], > ($owner == $a_row[owner]) ? "selected" : "", $a_row[owner]); > } > print "</select>"; > > What am I doing wrong in this code? Even when I take out the selected > stuff, I still get a value of 1 in the list instead of the actual > contents of the field. > > Any help is greatly appreciated! > __________________ > Jason Dulberg > Extreme MTB > http://extreme.nas.net First guess - try referencing the field values as $a_row["owner"] to avoid possible ambiguity; owner without the quotes could be a constant. Also, you can use extract to get the row values and stick them in variables named as the field names - makes your code a bit easier to read. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#47913) next »