4 Replies - 431 Views - Last Post: 24 March 2013 - 02:01 PM Rate Topic: -----

#1 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

remove product from the cart

Posted 24 March 2013 - 09:01 AM

i have a cart like this

		if(!isset($_SESSION['mycart']) || count($_SESSION['mycart']) < 1 )
		{
			$id = $_POST['pid'];
			
			
			
			$_SESSION['mycart'] = array(0 =>array("Product_ID" => $id, "Product_Name" => getName($id), "Price" => getPrice($id)));
		
			
		}
		else
		{
			$id = $_POST['pid'];
			
			
			
			array_push($_SESSION['mycart'],array("Product_ID" => $id, "Product_Name" => getName($id), "Price" => getPrice($id)));
		}
		


i have a separate delete button for each item when it clicks i want to delete the relevant sub array from the array any one give me a advice how do i delete the product row

Is This A Good Question/Topic? 0
  • +

Replies To: remove product from the cart

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2913
  • View blog
  • Posts: 10,092
  • Joined: 08-August 08

Re: remove product from the cart

Posted 24 March 2013 - 09:16 AM

Parallel arrays are a pain to manage. You'd be better off using a single array of objects where the product id was the key, then you'd only need to unset the $items[$key] to erase an item.
Was This Post Helpful? 3
  • +
  • -

#3 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

Re: remove product from the cart

Posted 24 March 2013 - 11:02 AM

okey how do i manage Quantity of a product from that type of array ?

This post has been edited by Dormilich: 25 March 2013 - 03:13 AM

Was This Post Helpful? 0
  • +
  • -

#4 Takk  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 111
  • Joined: 08-March 13

Re: remove product from the cart

Posted 24 March 2013 - 11:23 AM

edit: Yeah, new post.

Check out:
http://www.php.net/m....references.php

Some basis:
Creating an instance of a new class is the same as creating an instance of a new object
a custom class is the same as a custom object.


Look at the first example on that page, if you have only variables declared in the class, you will have generally a data object that can be stored in your array, any functions are additional in general, but may be helpful for readability

This post has been edited by Takk: 24 March 2013 - 01:05 PM

Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2913
  • View blog
  • Posts: 10,092
  • Joined: 08-August 08

Re: remove product from the cart

Posted 24 March 2013 - 02:01 PM

View Postistore221, on 24 March 2013 - 02:02 PM, said:

View PostCTphpnwb, on 24 March 2013 - 09:16 AM, said:

Parallel arrays are a pain to manage. You'd be better off using a single array of objects where the product id was the key, then you'd only need to unset the $items[$key] to erase an item.


okey how do i manage Quantity of a product from that type of array ?

Something $items[$key]->set_quantity($quantity); should work, assuming your items class has a setter method for quantity.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1