RE: [PHP] Is there an easier way?

From: Date: Fri, 01 Aug 2003 01:09:33 +0000
Subject: RE: [PHP] Is there an easier way?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-157856@lists.php.net to get a copy of this message
> if(!($rs = mysql_query($q))) // querying > { echo "Query failed". mysql_error(); exit; } > > > $n = 0; > while ($line = mysql_fetch_assoc($rs)) { //dumping into an array > foreach ($line as $field => $value) { > $data[$field][$n] = $value; > } > $n++; > } > > and this is how i use the arrays values (blah is the field name): > $blah1=$data['blah'][0]; > $blah2=$data['blah'][1]; > $blah3=$data['blah'][2]; This should work. Try it and see. $n = 0; while ($line = mysql_fetch_assoc($rs)) { //dumping into an array foreach ($line as $field => $value) { $tmp = $field.$n; $$tmp = $value; } $n++; }

« previous php.general (#157856) next »