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
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.