Skor Posted April 25, 2007 Share Posted April 25, 2007 ??? I think I've exceeded my knowledge threshold. I'm in the process of integrating Mal's Shopping Cart with my site and am unsure of how to take data that is sent and use it to update my inventory. One of the fields that is posted back is a field called cart. It includes all the items purchased in a single transaction. It looks something like this: First product description:1:9.99:0:QX001~Second product description:2:8.99:0:QT0045 cart Each product is delimited by a ~ and description, quantity, price, shipping units,stock code by colons : Blob What I'd like is basically a collection (an array?) of stock codes that will allow me to change the status of the codes in my data base through a relatively simple query-- change status to 'S' where code in ('QT0045','QX001'). My problem is that I more or less know what I want to do but am unsure in HOW to do it. I appreciate any guidance. Thanks. Link to comment https://forums.phpfreaks.com/topic/48579-solved-shopping-cart-data-parsing-question/ Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 does this help? $cart = $_POST['cart']; // breaks the string into an array of products $products = explode("~", $cart); $i = 0; // breaks each product string into its own array foreach($products as $var => $val){ $product[$i] = explode(":", $val); $code = $product[$i][4]; // if you want to update the status of codes, you can do it here // say you have a table named codes with code, status fields $update = "UPDATE codes SET `status`='S' WHERE `code`='$code'"; mysql_query($update) or die(mysql_error()); $i++; } Link to comment https://forums.phpfreaks.com/topic/48579-solved-shopping-cart-data-parsing-question/#findComment-237876 Share on other sites More sharing options...
Skor Posted April 25, 2007 Author Share Posted April 25, 2007 I'll give that a whirl. One question though. Do I need to account for the fact that each record is separated by the "~", but each data element within a record is separated by a ":" Just curious. Thanks. Link to comment https://forums.phpfreaks.com/topic/48579-solved-shopping-cart-data-parsing-question/#findComment-237880 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 that's what i was doing with the whole explode() function, those characters are removed from the resulting array values Link to comment https://forums.phpfreaks.com/topic/48579-solved-shopping-cart-data-parsing-question/#findComment-237885 Share on other sites More sharing options...
Skor Posted May 1, 2007 Author Share Posted May 1, 2007 This piece of code was real lifesaver. Thanks so much. Link to comment https://forums.phpfreaks.com/topic/48579-solved-shopping-cart-data-parsing-question/#findComment-242116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.