If I am fetching data from a MySQL database and using a while loop to iterate through the data how would I add each one to array?
$result = mysql_query("SELECT * FROM `Departments`");
while($row = mysql_fetch_assoc($result))
{
}
If I am fetching data from a MySQL database and using a while loop to iterate through the data how would I add each one to array?
|
|||
|
Build an array up as you iterate with the
Alternatively, if you used PDO, you could do this automatically. |
|||||
|
This will do the trick:
|
|||
|
This has been one of the fastest ways for me to create (multi-dimensional) arrays. I'm not sure if you want all of your results smooshed into one array or not.
You can use print_r($array) to see the results. |
||||
|