eddcaton Posted June 30, 2015 Share Posted June 30, 2015 Hello, I have done some work with PHP but just can't seem to find a solution to my problem. I would like to be able to make a ticket reservation system for a local charity. So what i would like to end up with is a form with text fields that will take the users details etc etc... << Which i have working. When the user comes to choosing how many tickets they want, it will give them 3 different tickets they can get and a text field of drop down menu next to them: Adult Kid Family (2 Adults + 2 Kids) So for an example the user has selected 1 adult and 2 kids i want to be able to insert 3 separate rows to one MYSQL table with the correct information on them (e.g. 1 Adult row and 2 Kids rows). Here is what is really confusing me as i don't know where i should start looking. If anyone has any ideas of where i can look.... or even if it can be done or not..... Thanks Edd Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/ Share on other sites More sharing options...
CroNiX Posted June 30, 2015 Share Posted June 30, 2015 You wouldn't want to store 3 separate rows. You'd store in a single row for the transaction, and that row would have a column for adult quantity and child quantity. Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1515321 Share on other sites More sharing options...
gizmola Posted June 30, 2015 Share Posted June 30, 2015 I don't see the "reservation" aspect of this app. What problem(s) are you actually trying to solve? You're down in the weeds and you have to start with the requirements of the app. Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1515323 Share on other sites More sharing options...
eddcaton Posted July 1, 2015 Author Share Posted July 1, 2015 (edited) The reason behind the seperate rows is that, i would like to have a reference number for each ticket which will be converted into a QR code that can be scanned at the entrance upon arrival. Edd Edited July 1, 2015 by eddcaton Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1515387 Share on other sites More sharing options...
scootstah Posted July 1, 2015 Share Posted July 1, 2015 There's several ways that you could structure your frontend to obtain the desired information. An easy one is to just put a quantity beside Adult and Kid. Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1515389 Share on other sites More sharing options...
eddcaton Posted July 1, 2015 Author Share Posted July 1, 2015 (edited) I have created a working form that has quantity next to adult and kid. I just want to be able to input a row into mysql for each ticket Edited July 1, 2015 by eddcaton Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1515390 Share on other sites More sharing options...
scootstah Posted July 1, 2015 Share Posted July 1, 2015 Then you need a for loop. http://php.net/manual/en/control-structures.for.php Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1515392 Share on other sites More sharing options...
EddNicks Posted July 15, 2015 Share Posted July 15, 2015 After reading many tutorials i really have no clue where to start on this... Could anyone lend me a hand?? Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516408 Share on other sites More sharing options...
ginerjm Posted July 15, 2015 Share Posted July 15, 2015 What do you have to show us so far? Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516417 Share on other sites More sharing options...
EddNicks Posted July 15, 2015 Share Posted July 15, 2015 Here is my html form that posts to my submit.php <table width="396" border="0"> <form action="submit.php" method="post"> <tr> <td width="44"> </td> <td colspan="2"><center><h2>A Bit About You..</h2></center></td> <td width="58"> </td> </tr> <tr> <td> </td> <td width="107"><p>Forename: </p></td> <td width="159"><input type="text" name="firstname" required></td> <td> </td> </tr> <tr> <td> </td> <td>Surname:</td> <td><input type="text" name="secondname" required></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td colspan="2"><center><h2>How Do We Get In Touch?</h2></center></td> <td></td> </tr> <tr> <td> </td> <td>Email Address:</td> <td><input type="text" name="email" required></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td colspan="2"><p><center><h2>When Are You Visiting?</h2></center></p></td> <td> </td> </tr> <tr> <td> </td> <td colspan="2"> <center> <select name="dayattending"> <option value="Saturday 16th">Saturday 16th</option> <option value="Sunday 17th">Sunday 17th</option> </select></center></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td colspan="2"><center><h2>Who's Coming?</h2></center></td> <td> </td> </tr> <tr> <td> </td> <td colspan="2"><center>Early Bird Discount <br /> Adult Ticket £2.50 <br /> Childrens Ticket (age 3-15) £0.50 <br /> Family Pass : £6.00 <br /><br /> </center></td> <td> </td> </tr> <tr> <td> </td> <td><center>Adult Ticket</center></td> <td><center>Childrens Ticket (age 3-15)</center></td> <td> </td> </tr> <tr> <td> </td> <td><center><input type="text" size = "2" name="adults" value="0"></center></td> <td><center><input type="text" size = "2" name="kids" value="0"></center></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td colspan="2"><center>Family Ticket (2 Adults & 2 Children)</center></td> <td> </td> </tr> <tr> <td> </td> <td colspan="2"><center><input type="text" size = "2" name="family" value="0"></center></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td colspan="2"><center><input type="submit"></center></td> <td> </td> </tr> </table> I am finding it really hard to get my head around the arrays as i have never used them before. If someone can give me an example i can try to build. I want to input each ticket as a single post in a MYSQL table so they can have their own booking number, which i will convert into a barcode to the public can be scanner in to the venue... Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516418 Share on other sites More sharing options...
scootstah Posted July 15, 2015 Share Posted July 15, 2015 (edited) You don't even need arrays, you just need to do some action * number of tickets. That is what a for loop is used for. $numAdults = $_POST['adults']; $numKids = $_POST['kids']; if ($numAdults != 0) { for ($i = 0; $i < $numAdults; $i++) { // create an adult ticket } } if ($numKids != 0) { for ($i = 0; $i < $numKids; $i++) { // create a kid ticket } }Rather than running an INSERT query on each loop iteration, though, I'd recommend that you compile a list of values to insert and do it all at once with a batch insert. Manual here. Edited July 15, 2015 by scootstah Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516419 Share on other sites More sharing options...
ginerjm Posted July 15, 2015 Share Posted July 15, 2015 1 - you are missing a closing form tag here. 2 - you want to post each single ticket with a separate booking number. That means a customer with 3 tickets has 3 booking numbers? Really? How will you tie the tickets to the purchaser? Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516420 Share on other sites More sharing options...
EddNicks Posted July 15, 2015 Share Posted July 15, 2015 Yes thats correct.. I will look at tying all the tickets together with a transaction id number or the payment email address that will be the same for all the tickets bought in that transaction. Then when a customer is logged into the online system they can see all of their tickets.... Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516423 Share on other sites More sharing options...
EddNicks Posted July 15, 2015 Share Posted July 15, 2015 (edited) So would the adults submit work something like this??? Obviously i will have to but a few lines in to connect to the DB but.. I have added a random number generator for now to make the transaction Number... $randomgen = mt_rand() . "\n"; echo mt_rand(10); $transaction_no = "$randomgen"; $numAdults = $_POST['adults']; $numKids = $_POST['kids']; if ($numAdults != 0) { for ($i = 0; $i < $numAdults; $i++) { // create an adult ticket mysqli_query($connect,"INSERT INTO tickets (ticket_type, transaction_no) VALUES ('$i','$transaction_no')"); } } Edited July 15, 2015 by EddNicks Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516428 Share on other sites More sharing options...
EddNicks Posted July 16, 2015 Share Posted July 16, 2015 So would the adults submit work something like this??? Obviously i will have to but a few lines in to connect to the DB but.. I have added a random number generator for now to make the transaction Number... $randomgen = mt_rand() . "\n"; echo mt_rand(10); $transaction_no = "$randomgen"; $numAdults = $_POST['adults']; $numKids = $_POST['kids']; if ($numAdults != 0) { for ($i = 0; $i < $numAdults; $i++) { // create an adult ticket mysqli_query($connect,"INSERT INTO tickets (ticket_type, transaction_no) VALUES ('$i','$transaction_no')"); } } Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516588 Share on other sites More sharing options...
scootstah Posted July 17, 2015 Share Posted July 17, 2015 mt_rand() is going to eventually produce duplicates. That is not a good way to do it. You'd probably want a "transactions" database table with the transaction number being the auto-incremented primary key. Of course, then the transaction numbers would be sequential, so if that is a problem you'll have to use something else. Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516599 Share on other sites More sharing options...
EddNicks Posted July 19, 2015 Share Posted July 19, 2015 Thanks scootstah .. Would the rest of the coding be correct?? Quote Link to comment https://forums.phpfreaks.com/topic/297125-do-i-need-arrays/#findComment-1516783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.