Forum Moderators: coopster
Usually it's as simple as ...
<?php$array = array('Some Text', 'Some More Text', 'Yes, you got it ... More Text');
$serialize_array = serialize($array);
mysql_query('INSERT INTO table SET field = "'.$serialize_array.'"');
?>
Then when pulling the data back out of the table, you should do something like this ...
<?$getRes = mysql_query('SELECT * FROM table');
while ($getRow = mysql_fetch_assoc($getRes)) {
$unserialized_array = unserialize($getRow['field']);
echo $unserialized_array[0]; // Outputs 'Some Text'
}?>
Thank you much for the reply. It helped really.
I have been able to save the array successfully in the DB.
However, The problem us retrieving it.
Can you please let me know, whats wrong in the following code:
<?php
mysql_connect("localhost","root");
mysql_select_db("arr_test");
$doquery=mysql_query("select * from arr_table");
while($getrow=mysql_fetch_array($doquery))
{
$var=unserialize($getrow['arr_all']);
echo $var[0];
}
?>
Because the result I am getting after executing this is simply the word "Array".