Jump to content

Unserialize data


bullbreed

Recommended Posts

Hi Guys

 

I'm trying (but failing) to unserialize some data in the database

 

I have 5 image urls stored as a serialized array

uploads/black.jpg

uploads/white.jpg

uploads/blue.jpg

uploads/red.jpg

uploads/pink.jpg

 

The images associated with these urls are in the uploads folder

 

How do I unserialize them and show them on screen. Here is my attempt (doesnt work)

[syntax=php]

<?php

if (isset($_GET['cid'])){

 

$sql = "SELECT * FROM `products` WHERE `prod_cat` = '".$_GET['cid']."' ";

$query = mysql_query($sql) or die(mysql_error());

 

if (mysql_num_rows($query) > 0) {

 

while ($row = mysql_fetch_assoc($query)){

 

$colours = unserialize($row['prod_colours']);

$itemcount = count($colours);

for ($i=0;$i<$itemcount;$i++) {

 

?>

<div class="image-select"><?php echo $colours[$i]; ?></a></div>

 

<?php

}

}

}

}

?>

[/syntax]

I get this notice

 

Notice: unserialize() [function.unserialize]: Error at offset 40 of 50 bytes in C:\xampp\htdocs\folders\includes\prodcontent.php on line 24.

 

But not sure what that is.

Link to comment
https://forums.phpfreaks.com/topic/193793-unserialize-data/
Share on other sites

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.