Unserialize - Having Troubles

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
mjjk91
-


Joined: 03 Feb 2004
Posts: 75
Location: Australia

PostPosted: Wed Jul 21, 2004 6:16 am    Post subject: Unserialize - Having Troubles Reply with quote

G'Day All,

I have made a script, which will serialize the products a user wishes to purchase, and then stores this serialized value in my database, but i am having troubles using the unserialize function to restore the original values, so i can use them again. For example, the user performs an order, and the products they wish to buy are stored in the database. On another page, the user wishes to print out a receipt of the products they bought, so i need to show them the products, by unserializing the value held in the database. Here are the main areas of my scripts:

-------------------------------------------------------------------------------------

(1) ordercomplete.php:

while($row = mysql_fetch_array($sql_get_cart)){
mysql_query("UPDATE shopping_products
SET product_qty = (product_qty - {$row['product_qty']})
WHERE product_id ='{$row['product_id']}'");

mysql_query("UPDATE shopping_products
SET sold = (sold + {$row['product_qty']})
WHERE product_id ='{$row['product_id']}'");

$product_qty_output[$count] = $row['product_qty'];
$product_price_output[$count] = $row['product_price'];
$product_title_output[$count] = $row['product_title'];

$storage_array[$row['product_id']]['qty'] = $row['product_qty'];
$storage_array[$row['product_id']]['price'] = $row['product_price'];
$storage_array[$row['product_id']]['name'] = $row['product_title'];


$count++;
}

$sproducts = serialize($storage_array);

-------------------------------------------------------------------------------------

(2) data held in the "products" field of the "shopping_cart_orders" table:

a:1:{i:5;a:3:{s:3:"qty";s:1:"1";s:5:"price";s:2:"12";s:4:"name";s:18:"Blues Baby Blanket";}}

-------------------------------------------------------------------------------------

(3) I want to unserialize the above to display the product(s) in a file called receipt_printer.php:

???

-------------------------------------------------------------------------------------

Any ideas how i can go about this?

Cheers

Mick Koch
Back to top View user's profile Send private message Visit poster's website MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sat Jul 24, 2004 2:15 am    Post subject: Re: Unserialize - Having Troubles Reply with quote

mjjk91,

http://www.php.net/manual/en/function.unserialize.php contains the manual of unserialize.

Normally, in receipt_printer.php, you should read the string $sproduct from the database and apply unserialize:

Code:
$storage_array = unserialize($sproduct);


$storage_array should be filled with the saved values.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
mjjk91
-


Joined: 03 Feb 2004
Posts: 75
Location: Australia

PostPosted: Wed Jul 28, 2004 5:36 am    Post subject: Half There Reply with quote

G'Day All,

Yep, i am able to load the value "products" into a variable, but when i try to display the contents of this unserialized variable, i cant. Obviously it has something to do with these lines:

$storage_array[$row['product_id']]['qty'] = $row['product_qty'];
$storage_array[$row['product_id']]['price'] = $row['product_price'];
$storage_array[$row['product_id']]['name'] = $row['product_title'];


But im not quite sure how to call the values. Any ideas?

Cheers

Mick Koch
Back to top View user's profile Send private message Visit poster's website MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Jul 29, 2004 12:26 am    Post subject: Re: Half There Reply with quote

mjjk91,

Please send us your PHP source code (of both files) and we'll try to find what's wrong.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
mjjk91
-


Joined: 03 Feb 2004
Posts: 75
Location: Australia

PostPosted: Fri Aug 06, 2004 3:21 am    Post subject: Files? Reply with quote

G'Day All,

Aprelium, did you get those files i sent you? How do they look? Any ideas about my unserialize problem. I have university this afternoon, and will ask questions there. Hopefully get a solution.

cheers

Mick Koch
Back to top View user's profile Send private message Visit poster's website MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Aug 09, 2004 1:25 am    Post subject: Re: Files? Reply with quote

mjjk91,

Yes, we've received the files but we've got no time to try them and find what's wrong. Sorry but we're very busy now with version 2.0. But answering your question is on our to do list and will get back to you ASAP.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group