If you know what your result set is going to be, it would be easier to
do something like this:

list($firstname,$lastname,$midinitial,$preferredname,$address1,$address2
,$city,$state,$zip) = mysql_fetch_row($result);

Or if you are returning more then one row, and want to loop through the
results:

while(list($firstname,$lastname,$midinitial,$preferredname,$address1,$ad
dress2,$city,$state,$zip) = mysql_fetch_row($result)) {
    
    // process the results as necessary...

}

-Dave

-----Original Message-----
From: Robert Weeks [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, December 12, 2001 7:03 AM
To: PHP List
Subject: [PHP-DB] question

Hi,

I'm a little stumped here, maybe I haven't had enough coffee yet.......

Anyway, I have a lot of SQL queries that return one row if there is a
match
and instead of having to write out something like this:

$firstname = $row["firstname"];
$lastname = $row["lastname"];
$midinitial = $row["midinitial"];
$preferredname = $row["preferredname"];
$address1 = $row["address1"];
$address2 = $row["address2"];
$city = $row["city"];
$state = $row["state"];
$zip = $row["zip"];

I thought I'd loop through the result and and get the info out like
this:

$nrows = mysql_num_rows($result);
$nfields = mysql_num_fields($result);
$rowarray = mysql_fetch_row($result);

for ($i=0; $i<$nfields; $i++){
$fname = mysql_fieldname($result,$i);
$val = $rowarray[$i];
$fname = $val;
}

and then later in the page reference the values using <?=$address1?>

Problem is this isn't working. If I echo the varibles to the page they
will
print out but they wont show up in the <?=$address1?> tags.

I tried setting the varibles to global and that still doesn't seem to
work.
I know I'm missing something really simple and basic here. If someone
could
give me a push in the right direction I'd appreciate it.

Thanks,

Robert


-- 
PHP Database 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 Database 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