views:

162

answers:

2

Hi, I have a database table as follows.

<table border='1'><th>Id</th><th>FirstName</th><th>last Name</th><tr><td>1</td><td>Tom</td><td>T</td></tr><tr><td>2</td><td>Jerry</td><td>J</td></tr></table>

I would like to store all values as a multi dimensional array using php(using a while loop to retrieve fields).That is, I would like the data to be echoed as:

array(array(1,Tom,T),array(2,Jerry,J));
A: 

You can use phps serialize function to convert any variable into a string representation

$string = serialize($dbData);

You can use unserialize() to convert the string back into arrays, objects, etc

$dbData = unserialize($string);

Once you have the data within a string, it's very easy to store in a file, db, etc. A disadvantage is that you won't be able to search your database easily for this data.

Ben Rowe
A: 
$result = mysql_query("SELECT * FROM tablename;");
while($result_ar = mysql_fetch_array($result)) {
    $multid_array[] = $result_ar;
}

after which $multid_array will be an array of arrays.

Amber