0

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!

1
  • What do you mean but it does'nt return all the values? Check the table through the mysql workbench or something to make sure the data is actually there. To unserialize you can use implode() on the arrays, or list() while looping thru them to assign each value to an variable Commented Mar 13, 2013 at 9:13

3 Answers 3

1

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);
Sign up to request clarification or add additional context in comments.

Comments

1

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]);
}

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.