Hi!
This is my first post. I'm trying to help a friend out with something but have kind of stepped in to some PHP which is slightly over my head, and so wanted to ask something. I am working on code that adds an item from a catalogue to a shopping basket. At the moment when the 'add to basket' button is pressed just one item is added to the basket. However, there are a few items that have a minimum quantity of 5 and so therefore would need to start at 5 instead of 1 for quantity. I will post all the relevant code below, but I was wanting to know what would be the best way to change this, should I create a new case? Or is there another way?
This is the initial button:
<a href="basket.php?action=add&id=' . $row['Product_ID'] . '"><img height="17" width="79" border="0" src="images/addtobasket.jpg" /></a>
This is the code for the 'add' action:
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
}
And then this is some of the function that displays the basket:
function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="basket.php?action=update" method="post" id="cart">';
$output[] = '<td><select name="qty'.$id.'" value="'.$qty.'"><option selected value="'.$multi1a.'">'.$multi1a.'</option><option value="'.$multi2a.'">'.$multi2a.'</option><option value="'.$multi3a.'">'.$multi3a.'</option></td>';
$output[] = '<div><button type="submit">Update cart</button></div>';
$output[] = '</form>';
}
return join('',$output);
}
Now what I've been trying to do is change the quantity from $qty to $multi1a. $multi1a is a value that represents the minimum quantity for my items, but it seems that the way the code works is that $qty will always be to the value of 1 when the page loads. After the page loads, if I use the update function it will then update to the value of $multi1a, but not unless I do that.
Does anyone have an idea of how I could best solve this?
Thanks so much for any help you can give!!!
Russ