Either 

1. Don't addslashes before you serialize it
2. use stripslashes before you unserialize it

> -----Original Message-----
> From: Jim Doolittle [mailto:[EMAIL PROTECTED]]
> Sent: Monday, December 03, 2001 9:07 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Can't unserialize array from mysql
> 
> 
> Hi,
> 
> I'm trying to loop thru an unserialized array pulled from 
> mysql. First I
> serialized the array before storing it:
> 
> --------------------------------------------------------------
> ----------
> 
> $sql ="UPDATE $table_name set performer_id='" . 
> addslashes(serialize($perfor
> mer_id)) . "' WHERE lineup_id=$lineup_id";
> 
> --------------------------------------------------------------
> ----------
> 
> This seems to work. mysql stores $performer_id as:
> 
> a:3:{i:0;s:2:"12";i:1;s:1:"1";i:2;s:1:"3";}
> 
> The next time I grab $performer_id from mysql I want to 
> unserialize it and
> loop thru it with foreach():
> 
> --------------------------------------------------------------
> ----------
> 
> $sql ="SELECT performer_id FROM lineup WHERE lineup_id=$lineup_id";
> 
> $result_pid = @mysql_query($sql, $connection) or 
> die("Couldn't execute query
> perfomer ID.");
> while ($row = mysql_fetch_row($result_pid)) {
> $result_pid = unserialize($result_pid);
> 
> foreach ($result_pid as $performer_id) {
> (some more code here)
> }
> --------------------------------------------------------------
> ----------
> 
> But this gives me an error "Warning: Invalid argument supplied for
> foreach()". I used var_dump before and after I unserialized 
> just to check
> that the result set actually contained data.
> 
> The first var_dump produced "array(1) { [0]=> string(44)
> "a:3:{i:0;s:2:"10";i:1;s:1:"6";i:2;s:2:"17";}" }". Looks 
> good, but var_dump
> after unserializing gives "bool(false)".
> 
> I also tried using reset() after the first var_dump, and 
> stripslashes(), but
> got the same error. Can anyone see what I'm doing wrong? Thanks!
> 
> Jim
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: 
> [EMAIL PROTECTED]
> 

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to