slaterino Posted January 16, 2010 Share Posted January 16, 2010 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! Link to comment https://forums.phpfreaks.com/topic/188686-some-help-needed-with-conditional-statement-adding-to-an-array/ Share on other sites More sharing options...
PHP Monkeh Posted January 16, 2010 Share Posted January 16, 2010 Maybe I haven't understood your code correctly, but isn't the if() statement just this: if($pricing == 'multi') { for($i=0; $i<$multi1a; $i++) { $cart .= "," . $_GET['id']; } } Link to comment https://forums.phpfreaks.com/topic/188686-some-help-needed-with-conditional-statement-adding-to-an-array/#findComment-996096 Share on other sites More sharing options...
slaterino Posted January 16, 2010 Author Share Posted January 16, 2010 That is exactly what I am after. Thank you very much! Link to comment https://forums.phpfreaks.com/topic/188686-some-help-needed-with-conditional-statement-adding-to-an-array/#findComment-996122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.