Jump to content

unserialize multiple rows and display


benluke

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
Link to comment
https://forums.phpfreaks.com/topic/20719-unserialize-multiple-rows-and-display/
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

Archived

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

×
×
  • Create New...

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.