Jump to content


Photo

Delete specific substring


  • Please log in to reply
1 reply to this topic

#1 ozzles2006

ozzles2006
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 October 2006 - 11:10 AM

I'm trying to build an e-commerce type website...

I couldn't get a "shopping cart" array to store in a session variable, so I gave up and started on cookies instead. So.. I have a string that I'm getting from a cookie. It's in the format "1,2,1,3,4,5" and so on (no particular order) depending on what's been put into it.

I'm just wondering if theres any way to delete, for example, 1 instance of "2," or "5"? I can do it to remove all entries, but I only want it to do it once.

#2 ozzles2006

ozzles2006
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 October 2006 - 11:14 AM

Thought I should post the bit of code I'm dealing with.

$cart=$_COOKIE['cart'];
$item = $_POST['id'];
$qty = $_POST['qty'];

if (strlen($cart)==1) {

setcookie('cart','');
echo "<meta content='0;url=index.php?p=checkout' http-equiv='refresh' />";

} else {

$cart = explode("|", $_COOKIE['cart']);
$cart_count = array_count_values($cart);

foreach ($cart_count as $itemNum => $qty) {

}
echo "<meta content='0;url=index.php?p=checkout' http-equiv='refresh' />";
}

Basically what I'm doing is using the array_count_values method to "group by" the item number.
So what I want to do is reduce the quantity for the item corresponding to the button that's been pressed and then regenerate the string and add it to the cookie again.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users