Reputation: 5228
I have a SQL column where i store serialized values. I want to interogate the table, get all the column values, unserialize them and then work on the data in the resulted array.
$g1 = mysql_query("SELECT q4 FROM qa");
$g2 = (mysql_fetch_array($g1));
but $g2 don't return all the column values. Also, after i get all the values in a $g2 array, how i should unserialize the resulted array of arrays? Thank you!
Upvotes: 0
Views: 2521
Reputation: 3654
You need to iterate over the rows
like:
$g1 = mysql_query("SELECT q4 FROM qa");
$g2 = Array();
while($row = (mysql_fetch_array($g1))) {
$g2[] = $row;
}
assuming you serialized the data with PHP the answer is the unserialize()
method
Upvotes: 0
Reputation: 66650
if q4 is string serialized using serialize function then you need to use unserialize function.
$g2 = array();
foreach(mysql_fetch_array($g1) as $row) {
$g2[] = unserialize($row[0]);
}
Upvotes: 1
Reputation: 32820
Try this :
$g1 = mysql_query("SELECT q4 FROM qa");
$val = array();
while($g2 = mysql_fetch_array($g1)){
$val[] = unserialize($g2['q4']);
}
echo "<pre>";
print_r($val);
Upvotes: 1