Use string stored in db as an array

February 25, 2009 at 08:43:46
Specs: Macintosh
Hi All,

I'm trying to write a script to generate rows in a table from arrays and sub-arrays.

Its all working lovely but i've come up against a problem... all i want to do is store the full array string in a database then retrieve it to use when its needed, the problem is that the retrieved string just acts as a string and not a set of arrays!!

This is what i'm trying to store, it should be self explanetory...

array("Field1","Field2","Field3","Field4"), array("row1","row1","row1","row1"), array("row2","row2","row2","row2"), array("row3","row3","row3","row3"), array("row4","row4","row4","row4")

this generates a 4 x 5 table in the final script but only when it is coded into the PHP as arrays.

$data = array(array("Field... works

$data = $string_from_db doesn't

See More: Use string stored in db as an array

Report •

February 26, 2009 at 01:57:53
Okay sorted it...

Run the array through serialize() in PHP before storing it into the MySQL DB - then when you retrieve it you can unserialize() it and hey-presto its an array again.

Lovely PHP.

Report •
Related Solutions

Ask Question