Update page using some form of PHP function

Okay,
Currently my code always adds just one item to my shopping basket at a time, which is completely fine for most items. However there are a few items that are in multiples, and are therefore only available in quantities of 5, 10 and 20. I have altered my code slightly so that when looking in the basket customers can change the quantities solely to these amounts but have a problem as when the basket page is opened the quantity always defaults to 1 item, even though it may show in the basket as 5. It is then necessary to click the ‘Update Cart’ button to refresh the amount. My question then is thus: what can I add to the script so that the update cart function is run as soon as the page loads? As this to me seems like the easiest way to do it.

This is my script below. I want the mutliple items to default to the value of $multi1a and not to $qty (as when the page loads $qty will always be the value of 1)

			$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>';
			}	
	        if ($pricing == "Multi")
			{
			if ($qty == $multi1a) {
			$output[] = '<td>&pound;'.($multi1b).'</td>';
			$total += ($multi1b);
			}
			if ($qty == $multi2a) {
			$output[] = '<td>&pound;'.($multi2b).'</td>';
			$total += ($multi2b);
			}
			if ($qty == $multi3a) {
			$output[] = '<td>&pound;'.($multi3b).'</td>';
			$total += ($multi3b);
			}
			}
			else {
			$output[] = '<td>&pound;'.(($Price) * $qty).'</td>';
			$total += ($Price) * $qty;
			}
			$output[] = '</tr>';
		}
		$sum = array_sum($contents);
		$output[] = '</table>';
		$output[] = '<p>Grand total: <strong>&pound;'.$total.'</strong></p>';
		$output[] = '<div><button type="submit">Update cart</button></div>';
		$output[] = '</form>';

Thanks!!

as when the page loads $qty will always be the value of 1

why don’t you change this behavior?
What HTML do you use for quantity selection? just give name “qty” for the field

And, I can’t help it, but these $output scares me to death

Well,
I really liked the way the page was working as basically it gets the ‘id’ for the item and then adds 1 to the quantity for it. I think to take it apart could really be painful. But anyway, I have posted both the ‘add’ function and the ‘update’ function as hopefully these will help in trying to find a solution.

switch ($action) {
	case 'add':
		if ($cart) {
			$cart .= ','.$_GET['id'];
		} else {
			$cart = $_GET['id'];
		}
		break;
	case 'update':
	if ($cart) {
		$newcart = '';
		foreach ($_POST as $key=>$value) {
			if (stristr($key,'qty')) {
				$id = str_replace('qty','',$key);
				$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
				$newcart = '';
				foreach ($items as $item) {
					if ($id != $item) {
						if ($newcart != '') {
							$newcart .= ','.$item;
						} else {
							$newcart = $item;
						}
					}
				}
				for ($i=1;$i<=$value;$i++) {
					if ($newcart != '') {
						$newcart .= ','.$id;
					} else {
						$newcart = $id;
					}
				}
			}
		}
	}
	$cart = $newcart;
}
	break;