Page 1 of 1

Store array in db

Posted: Fri Sep 24, 2004 10:27 pm
by anjanesh
Is there anyway to store this in a mysql table such that when retrieving it in mysql_fetch_assoc() I should be able to use the result as an array

Code: Select all

$array=array(
array("Key1"=>"Value1","Key2"=>"Value06","Key3"=>"Value11"),
array("Key1"=>"Value2","Key2"=>"Value07","Key3"=>"Value12"),
array("Key1"=>"Value3","Key2"=>"Value08","Key3"=>"Value13"),
array("Key1"=>"Value4","Key2"=>"Value09","Key3"=>"Value14"),
array("Key1"=>"Value5","Key2"=>"Value10","Key3"=>"Value15")
);

Code: Select all

$row=mysql_fetch_assoc($res);
$arr=$row['array']
echo $arr[2]['Key2'];

Posted: Fri Sep 24, 2004 10:34 pm
by Weirdan
you can use [php_man]serialize[/php_man] to store any complex structure in a string. Just make sure you have that column in db large enough.

Posted: Fri Sep 24, 2004 10:49 pm
by feyd
if the structure of it is pretty much the same, I wouldn't store such a large amount of data in one single field. Instead, I'd break the structure apart into it's own columns or table, whichever is better for the situation.