Re: [PHP] populating dropdown list problems

2001-04-09 Thread David Robley

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 "";
> $result = mysql_query("SELECT owner,agent FROM homes;");
> while($a_row = mysql_fetch_array($result))
> {
>   printf(' value="'.$a_row[owner].'">'.$a_row[owner].'', $a_row[owner],
> ($owner == $a_row[owner]) ? "selected" : "", $a_row[owner]);
> }
> print "";
>
> 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]




[PHP] populating dropdown list problems

2001-04-09 Thread Jason Dulberg

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 "";
$result = mysql_query("SELECT owner,agent FROM homes;");
while($a_row = mysql_fetch_array($result))
{
printf(''.$a_row[owner].'', $a_row[owner],
($owner == $a_row[owner]) ? "selected" : "", $a_row[owner]);
}
print "";

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


-- 
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]