How to get all rows in an array

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

How to get all rows in an array

Post by m2babaey »

Hi
I want to get table records all in 1 array. I used mysql_fetch_array() but it was returing the first record only
How can all records be stored in 1 array?
I have table: symbols1 and symbols2; I want to get all of their data and then use array_merge() to combine the data
Thanks for your help
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: How to get all rows in an array

Post by robnet »

mysql_fetch_array() will return one row as an array. The next time you call mysql_fetch_array() it will load the second row and so on until there are no more rows in the result set.

Use this:

Code: Select all

<?php
while ($row=mysql_fetch_array($result)){
 // do stuff with new array: $row
}
?>
Within the while loop you can merge your rows or whatever you like.
Post Reply