Jump to content

Archived

This topic is now archived and is closed to further replies.

benluke

unserialize multiple rows and display

Recommended Posts

Hi,

Going back sometime now and after posting on php freaks you helped me out with the following code (much appreciated)

[code]
<?php


  $sql = "SELECT knowledge_1 knowledge_2 knowledge_3 knowledge_4 knowledge_5 knowledge_6 knowledge_7 knowledge_8 knowledge_9 knowledge_10 knowledge_11 knowledge_12 knowledge_13 knowledge_14 FROM HS31 WHERE userid = $userid LIMIT 1";
  if ($result = mysql_query($sql)) {
    $row = mysql_fetch_assoc($result);
$array = array();
    $array = unserialize($row['knowledge_1']);
    print_r($array);
  } else {
  echo "there was a problem";
  }

?>
[/code]

Which displays

[code]
Array ( [0] => A [1] => B [2] => C [3] => D )
[/code]

My question is this.
What do i need to add / change so that it displays every array from each table row?


Benluke

Share this post


Link to post
Share on other sites
probably just
[code]SELECT *[/code]
rather than all of the fields
then use a while loop to get each row and probably an explode function to echo each array so:
[code]
$sql=mysql_query("SELECT * FROM HS31");
echo 'Array :<br>';
while ($row=mysql_fetch_array($sql)){
foreach ($row as $id=> $v)
{
echo $id'. => '.$v.'<br>';
}
}
[/code]
Not tested that, but think it'll work

Share this post


Link to post
Share on other sites
Its giving me the following error:
[code]
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/n/v/nvq/public_html/nvq/hs31/knowledge_display.php on line 29
[/code]

Thanks for your help gerkintrigg.
Benluke

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.