Page 1 of 1

Booking Lanes in Alley - how do you do this in Code?

Posted: Wed Feb 29, 2012 4:54 am
by simonmlewis
Hi.

I've been asked to build a system where you select the Checkboxes for lanes/Times of a bowling alley.
Once selected, you click Submit and it passes you over to the next page where you are shown the lanes you booked, and then taken to PayPal to pay the fee.

Each lane is always the same price. So a 'count' of selections can get the cost easy: 2 X £5 = Charges £10.

But what I cannot work out is the best way to pass these box's values thru. Do I do it with 48 (that's the maximum variant of selections available): $l1_1030=$_POST['l1_1030'];??

And then on the next page do a session:

Code: Select all

if(isset($_POST['l1_1030']))
{
    $l1_1030 = $_POST['l1_1030'];
    $_SESSION['l1_1030']=$l1_1030;
} else { $l1_1030=$_SESSION['l1_1030'];
}
(48 times!!!)
And at the foot of the final paid page, do this:
unset($_SESSION['$l1_1100']);
(48 times!!!)

??

This looks like nightmare code to run and manage.

Re: Booking Lanes in Alley - how do you do this in Code?

Posted: Wed Feb 29, 2012 1:04 pm
by temidayo
Create a database. Put the details of each checkboxes in a row with a unique name.

When you display your form, make the checkboxes as array with the same name but give each checkbox
their unique name database name as value.

When the form is submitted, check(using foreach loop) for checked boxes, retrieve their values
use the value of each to get their details from the database.

I hope that helps

Re: Booking Lanes in Alley - how do you do this in Code?

Posted: Wed Feb 29, 2012 1:32 pm
by simonmlewis
Thanks. For 48 options (checkboxes) that's some hefty code. not sure how I would do as a foreach, when each checkbox is diff name.

Re: Booking Lanes in Alley - how do you do this in Code?

Posted: Wed Feb 29, 2012 2:28 pm
by temidayo
Let's assume you have created your array of checkboxes with a single name
checkboxname
Once the form is submitted, process this way:

Code: Select all

$checkboxname = $_POST['checkboxname'];
foreach($checkboxname as $key => $value){//value is one for a checked box...key is wat is needed
			//do stuffs here
		}