RE: [PHP] array question

From: Date: Thu, 19 Jul 2001 17:45:10 +0000
Subject: RE: [PHP] array question
Groups: php.general 
Request: Send a blank email to php-general+get-58758@lists.php.net to get a copy of this message
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:jwgreene@megalink.net] 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: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#58758) next »