gdfhghjdfghgfhf Posted April 5, 2008 Share Posted April 5, 2008 i have an entry in my database with a lot of serialized things it looks like this: a:2:{i:1;s:6:"blablablabla1";i:2;s:6:"blablablabla2";} i'm trying to make it more human-readable, and i would also make each word linkable so instead of the serialized thing it would look like this: <a href="blablablabla1.php">blablablabla1</a><br> <a href="blablablabla2.php">blablablabla2</a><br> but i can't even manage to unserialize it i tryed with this: mysql_connect($server, $user, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $query = "SELECT * FROM calendarcustomfield"; $res = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($res)) { $options = $row["options"]; echo unserialize($options); } but it always returns "Array" nothing else... it just displays the word Array could someone help me please? Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 5, 2008 Share Posted April 5, 2008 mysql_connect($server, $user, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $query = "SELECT * FROM calendarcustomfield"; $res = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($res)) { $options = $row["options"]; print_r(unserialize($options)); } use print_r to print array variables, see if it helps, Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted April 5, 2008 Author Share Posted April 5, 2008 hmm now i get something weird Array ( [1] => blablablabla1 [2] => blablablabla2 ) how can i take out the useless stuff id like it to appear as <a href="blablablabla1.php">blablablabla1</a><br> <a href="blablablabla2.php">blablablabla2</a><br> Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 5, 2008 Share Posted April 5, 2008 this is called an array. you can use arrays like so: $array['array_key'] = "value"; foreach($array As $array_item){ echo($array_item); } to incorporate this you could try: mysql_connect($server, $user, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $query = "SELECT * FROM calendarcustomfield"; $res = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($res)) { $options = unserialize($row["options"]); foreach($options As $option){ echo("<a href=\"$option.php\">$option</a><br />\n"); } } hope this helps Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted April 5, 2008 Author Share Posted April 5, 2008 wonderful! exactly what i wanted to do thanks a lot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.