[solved] database / serialize / unserialize / arrays... WHOA
Posted: Thu Oct 20, 2005 5:09 pm
Hey everyone
I'm new to the forum. I have tried everything that I know to solve this problem.
I'm making a clothing catalog. The problem I'm having is when I serialize an array of shirt sizes and quantities, I can't get a clean look at it. There's got to be something wrong with the following code or my logic.
I'm new to the forum. I have tried everything that I know to solve this problem.
I'm making a clothing catalog. The problem I'm having is when I serialize an array of shirt sizes and quantities, I can't get a clean look at it. There's got to be something wrong with the following code or my logic.
Code: Select all
//this is what the serialized array looks like when echoed
//a:7:{s:2:"xs";i:30;s:2:"sm";i:31;s:2:"md";i:32;s:2:"lg";i:33;s:2:"xl";i:32;s:3:"xxl";i:31;s:4:"xxxl";i:30;}
$result = mssql_query("SELECT array FROM arrays WHERE id='8'");
$serialarray = mssql_fetch_array($result);
echo "ATTEMPT TO TRAVERSE THE SERIALIZED ARRAY<br>";
$a = $serialarray;
$a = unserialize($a);
// Key = shirt size, Value = quantity
while (list($key, $value) = each($a))
{
echo "Key: ". $key ." > Value: ".$value."<br>";
}
// should print out this:
//Key: xs > Value: 30
//Key: sm > Value: 31
//Key: md > Value: 32
//Key: lg > Value: 33
//Key: xl > Value: 32
//Key: xxl > Value: 31
//Key: xxxl > Value: 30