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:


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!


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