Jump to content


Photo

unserialize multiple rows and display


  • Please log in to reply
2 replies to this topic

#1 benluke

benluke
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 September 2006 - 11:40 AM

Hi,

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

<?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";
  }

?>

Which displays

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

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


Benluke


#2 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 14 September 2006 - 01:15 PM

probably just
SELECT *
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:
$sql=mysql_query("SELECT * FROM HS31");
echo 'Array :<br>';
while ($row=mysql_fetch_array($sql)){
foreach ($row as $id=> $v)
		{
		echo $id'. => '.$v.'<br>';
		}
}
Not tested that, but think it'll work
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#3 benluke

benluke
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 September 2006 - 01:28 PM

Its giving me the following error:
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

Thanks for your help gerkintrigg.
Benluke





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users