|
-
March 31st, 2011, 04:55 PM
#1
mysql get rows
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
Code:
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?
-
March 31st, 2011, 05:18 PM
#2
Re: mysql get rows
Nope. MySQL itself can only read one line of data at a time...hence why you have to recurse it.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 31st, 2011, 05:20 PM
#3
Re: mysql get rows
 Originally Posted by [email protected]
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
Code:
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?
Code:
while($data[] = mysql_fetch_array($res) ) {}
array_pop($data);
seems to work
-
March 31st, 2011, 06:22 PM
#4
Re: mysql get rows
But, you're still creating the array one index at a time. You said you didn't want to do that.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|