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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to