Click to See Complete Forum and Search --> : mysql get rows


niladhar8@gmail.com
March 31st, 2011, 04:55 PM
sorry not sure if i can publish a question on mysql here...

on a query that returns n number of rows can i do it in a single statement instead of looping through...

right now this is what i do



while($data = mysql_fetch_array($res) )
{
$temp['name'][] = $data['name'];
$temp['state'][] = $data['state'];
$temp['street'][] = $data['street'];
$temp['number'][] = $data['number'];

}


cant i have mysql automatically put them all in an array for me?

PeejAvery
March 31st, 2011, 05:18 PM
Nope. MySQL itself can only read one line of data at a time...hence why you have to recurse it.

niladhar8@gmail.com
March 31st, 2011, 05:20 PM
sorry not sure if i can publish a question on mysql here...

on a query that returns n number of rows can i do it in a single statement instead of looping through...

right now this is what i do



while($data = mysql_fetch_array($res) )
{
$temp['name'][] = $data['name'];
$temp['state'][] = $data['state'];
$temp['street'][] = $data['street'];
$temp['number'][] = $data['number'];

}


cant i have mysql automatically put them all in an array for me?

while($data[] = mysql_fetch_array($res) ) {}
array_pop($data);

seems to work :)

PeejAvery
March 31st, 2011, 06:22 PM
But, you're still creating the array one index at a time. You said you didn't want to do that.