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?
| |||
feedback
|
Build an array up as you iterate with the
Alternatively, if you used PDO, you could do this automatically. | |||||||
feedback
|
This will do the trick:
| |||
feedback
|
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. | ||||
feedback
|
Alternatively you can use my function to do that:
Usage:
Pretty handy. | |||
feedback
|