Try using mysql_fetch_array instead of mysql_fetch_object.

You then then use a simple loop to assign your variables
e.g.

foreach($row as $k=>$v)
{
   $GLOBALS[$k] = $v; // or $GLOBALS[$k][$i++] = $v if multiple records
being read
}

This will result in a set of global variables matching your database fields
names.

-Stewart

-----Original Message-----
From: James W Greene [mailto:[EMAIL PROTECTED]]
Sent: 19 July 2001 18:37
To: php-general
Subject: [PHP] array question


Hi All,
    I am trying to pull info out of a table and assign a var name to each
field...  I seem to be having trouble.  I have tried to do $var = $row[0]
but that does not seem to do it.  I have included what is working below.  I
would like to have each element of the array stored in a seperate variable
for use on a  web page. Thanks
JG

<?php
$stmt = 'SELECT * FROM custdata WHERE UserName like "fred"';
mysql_connect($localhost,test,testme);
$result = mysql_db_query("test",$stmt) ;
while($row = mysql_fetch_object($result)) {
//** doing this now**//
printf("%s",
 $row->UserName) ;
// **Would like to do something like**//
// $user = $row[0]; //

}
mysql_free_result($result);
?>


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