user1508136
user1508136

Reputation: 57

Array from Database PHP

Hi I need to create an array from database; myTable looks like this

id           | name       | address |
-------------+------------+---------------
1            | Peter      | Union Streeet|
2            | John       | King Street  | 

Then I have sql that will select values from database

$record=mysql_query("SELECT * FROM myTable");
while($row=mysql_fetch_assoc($record)){
      //fill array how to fill array that will look like bellow from database???
}

I need to create array that will look like this

$list = array (
    array('$row[id]', '$row[name]', '$row[address]'),
    // array('$row[id]', '$row[name]', '$row[address]')
    // FOR EACH LINE FROM DATABASE NEW NESTED ARRAY
);

Upvotes: 1

Views: 21510

Answers (2)

Prasanth Bendra
Prasanth Bendra

Reputation: 32740

Try this :

while($row=mysql_fetch_assoc($record)){
     $list[] = $row;
}

echo "<pre>";
print_r($list);

Upvotes: 3

peter.svintsitskiy
peter.svintsitskiy

Reputation: 322

$record=mysql_query("SELECT * FROM myTable");
$list = array();
while($row=mysql_fetch_assoc($record)){
      //fill array how to fill array that will look like bellow from database???
    $list[] = row;
}

Upvotes: 6

Related Questions