up vote 0 down vote favorite

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));
link|flag

79% accept rate

2 Answers

up vote 0 down vote accepted
$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.

link|flag
up vote 0 down vote

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.

link|flag

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.