Jump to content

Some help needed with conditional statement adding to an array


slaterino

Recommended Posts

Hi,

I have a script that adds the id of a product to an array and I then use this script to calculate the quantity. This is the script for adding the ID number to the array:

 

		if ($cart) {
		$cart .= ','.$_GET['id'];
	} else {
		$cart = $_GET['id'];
	}

 

However I have a few items that cannot have a minimum quantity of 1. There are a variety of different minimums that they could have and these are all stored in my database as the value $multi1a. These items are also distinguished from those that can have a quantity of 1 by having a $pricing value of 'multi'. As my shopping cart, using the code above, is only adding one item to the quantity when it adds an item to the cart I need to change this for these other items. So that for example, if an item had a minimum quantity of 5, meaning $multi1a = 5, the code would work like this:

 

		if ($cart) {
		$cart .= ','.$_GET['id']','.$_GET['id']','.$_GET['id']','.$_GET['id']','.$_GET['id'];
	} else {
		$cart = $_GET['id']','.$_GET['id']','.$_GET['id']','.$_GET['id']','.$_GET['id'];
	}

 

If the minimum quantity was 10 there would obviously be 10 sets of $_GET['id'] in the code. The thing is that minimum quantity could be anything the user sets so I need a way that this would be done automatically after taking the value of $multi1a. I know how to start this, which would be something like:

 

$sql = 'SELECT pricing, multi1a FROM products WHERE Product_ID = '.$GET['id'];
	$result = mysql_query($sql) or die(mysql_error());
	while(list($pricing, $multi1a)= mysql_fetch_row($result))
{
                if($pricing == 'multi')
                {THIS IS THE BIT I NEED HELP WITH}
}
else
{
if ($cart) {
		$cart .= ','.$_GET['id'];
	} else {
		$cart = $_GET['id'];
	}
}

 

Does that make sense? If anyone can help with this they will have my eternal gratitude!

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.