Jump to content

help with unserialize();


gdfhghjdfghgfhf

Recommended Posts

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?

Link to comment
Share on other sites

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, :)

Link to comment
Share on other sites

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 ;)

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.