PHP/MySQL: How to Create Two Dimensional Arrays from Database Record

Author: Zeeshan Arshad     911     07/22/2013

Estimated reading time: 0 minutes, 11 seconds

1. Fetch database record


$result = mysql_query("SELECT id, title FROM table");


2. Do a while loop


while ($row = mysql_fetch_array($result)) {
$my_array[] = array('id' => $row['id'], 'text' => $row['title']);


There you go : )

Was this topic helpful?

Subscribe YouTube Channel

Zeeshan Arshad is a self-taught and multi-dimensional person with extraordinary track record of success with international clients and students.

Feel free to contact him for your project, training purpose or guidance.