ben_1uk Posted March 12, 2012 Share Posted March 12, 2012 Hi everyone, I'm hoping somebody can help me out with a change I need to make to a website that I have not designed / coded myself. I have been asked to remove a "ticket counter" advertising the number of tickets left available for a number of upcoming events. I have included a copy of the .php file that is handling the ticket counter iteself below. <?php include('includes/includes_begin.php'); echo "<div id='heading'><h1><img src='images/tickets.gif' width='178' height='48' alt='Tickets' title='Tickets' /></h1></div>"; $page_title = "Tickets"; if (isset($_SESSION['checkout'])) { $_SESSION['checkout'] = false; } $conn = new dbConnect('private'); $query = "SELECT id, venue_name, venue_address, UNIX_TIMESTAMP(match_date) as m_date, tickets_left FROM venues WHERE sales_closed = 0 ORDER BY match_date ASC"; $venues = $conn->dbAll($query); $conn->dbClose(); if (count($venues) == 0) { echo "<div class='error'>There are no more tickets available to buy</div>"; } else { echo " <form method='post' action='summary.php'>"; $venuecount = 0; foreach ($venues as $v) { echo "<div class='venue'> <div class='match_date'><b>Match Date:</b> " . date(ymd, $v['m_date']) . "</div> <h2>" . escape($v['venue_name']) . "</h2> <div class='venue_address'>" . nl2br(escape($v['venue_address'])) . "</div> <div class='tickets_container'> <div class='tickets'>" . ($v['tickets_left'] < 30 ? "<span class='tickets_low'>" . escape($v['tickets_left']) . "</span>" : "" . escape($v['tickets_left']) . "") . " tickets left to buy for this match</div>"; if ($v['tickets_left'] > 0) { echo " <div class='tickets_buy'> <input type='hidden' name='venue[]' value='" . escape($v['id']) . "' /> Select how many tickets you wish to buy <select name='quantity[]' id='venue_" . escape($venuecount) . "' onchange='update_tickets()' onkeyup='update_tickets()'> <option value='0'>No tickets</option> <option value='1'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '1' ? " selected='selected'" : "") . ">1 ticket</option> " . ($v['tickets_left'] > 5 ? " <option value='2'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '2' ? " selected='selected'" : "") . ">2 tickets</option> <option value='3'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '3' ? " selected='selected'" : "") . ">3 tickets</option> <option value='4'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '4' ? " selected='selected'" : "") . ">4 tickets</option> <option value='5'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '5' ? " selected='selected'" : "") . ">5 tickets</option>" : "") . " </select> <a href='#buy'>Confirm Ticket</a> </div> "; $venuecount++; } echo " </div> </div> <hr />"; } echo "<input type='hidden' id='venue_count' name='venuecount' value='" . escape($venuecount) . "' /> <div id='buy'></div><noscript><input type='submit' id='selecttickets' name='submit' value='' title='Select these tickets'/></noscript></form> "; if (isset($_SESSION['tickets']) && array_sum($_SESSION['tickets']) > 0) { echo "<script type='text/javascript'>update_tickets();</script>"; } } include('includes/includes_end.php'); ?> I have a limited understanding of how the ticket counter works in principal, but I'm anxious to start removing sections of code in case of unsuspected knock-on effects. I want to leave the number of tickets people can purchase for an event intact - I just need to remove the ticket counter itself. Can anybody offer any help? Many thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/ Share on other sites More sharing options...
sunfighter Posted March 13, 2012 Share Posted March 13, 2012 The php you gave us outputs this: Match Date: The Date Here venue_name venue_address (The Number of Tickets Left) tickets left to buy for this match --------------------------------------------------------------------------------------------- For every venue. Is it the bottom line you want removed ? Then what do you want to remain? Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1326922 Share on other sites More sharing options...
QuickOldCar Posted March 13, 2012 Share Posted March 13, 2012 All you have to do is not display the areas that are showing how many tickets are left, this is the data coming from the database. Comment out this section like below, I think is what you are after. /* echo "<div class='venue'> <div class='match_date'><b>Match Date:</b> " . date(ymd, $v['m_date']) . "</div> <h2>" . escape($v['venue_name']) . "</h2> <div class='venue_address'>" . nl2br(escape($v['venue_address'])) . "</div> <div class='tickets_container'> <div class='tickets'>" . ($v['tickets_left'] < 30 ? "<span class='tickets_low'>" . escape($v['tickets_left']) . "</span>" : "" . escape($v['tickets_left']) . "") . " tickets left to buy for this match</div>"; */ Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1326924 Share on other sites More sharing options...
ben_1uk Posted March 14, 2012 Author Share Posted March 14, 2012 Thanks for the replies both - I really appreciate it. sunfighter: The php you gave us outputs this: Match Date: The Date Here venue_name venue_address (The Number of Tickets Left) tickets left to buy for this match --------------------------------------------------------------------------------------------- For every venue. Is it the bottom line you want removed ? Then what do you want to remain? The line I want to remove from the code is 'XXX tickets left to buy for this match'. QuickOldCar: All you have to do is not display the areas that are showing how many tickets are left, this is the data coming from the database. Comment out this section like below, I think is what you are after. If I 'comment out' all of the above code, surely it will also remove the match date, venue name, venue address and ticket container? All I want to remove is the line that confirms how many tickets are left. Can I simply comment out the code as follows: /*<div class='tickets'>" . ($v['tickets_left'] < 30 ? "<span class='tickets_low'>" . escape($v['tickets_left']) . "</span>" : "" . escape($v['tickets_left']) . "") . " tickets left to buy for this match</div>"; */ Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1327140 Share on other sites More sharing options...
QuickOldCar Posted March 14, 2012 Share Posted March 14, 2012 What I did was add the closing double quotes and semicolon to the last line being displayed. The commented line I made a new line with echo, now can just comment and uncomment it if need to. echo "<div class='venue'> <div class='match_date'><b>Match Date:</b> " . date(ymd, $v['m_date']) . "</div> <h2>" . escape($v['venue_name']) . "</h2> <div class='venue_address'>" . nl2br(escape($v['venue_address'])) . "</div> <div class='tickets_container'>"; //echo "<div class='tickets'>" . ($v['tickets_left'] < 30 ? "<span class='tickets_low'>" . escape($v['tickets_left']) . "</span>" : "" . escape($v['tickets_left']) . "") . " tickets left to buy for this match</div>"; Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1327176 Share on other sites More sharing options...
ben_1uk Posted March 15, 2012 Author Share Posted March 15, 2012 What I did was add the closing double quotes and semicolon to the last line being displayed. The commented line I made a new line with echo, now can just comment and uncomment it if need to. echo "<div class='venue'> <div class='match_date'><b>Match Date:</b> " . date(ymd, $v['m_date']) . "</div> <h2>" . escape($v['venue_name']) . "</h2> <div class='venue_address'>" . nl2br(escape($v['venue_address'])) . "</div> <div class='tickets_container'>"; //echo "<div class='tickets'>" . ($v['tickets_left'] < 30 ? "<span class='tickets_low'>" . escape($v['tickets_left']) . "</span>" : "" . escape($v['tickets_left']) . "") . " tickets left to buy for this match</div>"; So, if I punctuate the original source code exactly as above, everything will remain intact, but the number of tickets left available for sale will not be displayed? It will have no effect on people being able to select the number of tickets they wish to purchase or data being posted to the SQL database? Sorry for the silly questions, but not having coded this myself, I really don't want to mess it up! Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1327571 Share on other sites More sharing options...
QuickOldCar Posted March 15, 2012 Share Posted March 15, 2012 You are correct, it is just commenting out the displaying of the tickets left. Everything else should function the same. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1327619 Share on other sites More sharing options...
ben_1uk Posted March 15, 2012 Author Share Posted March 15, 2012 You are correct, it is just commenting out the displaying of the tickets left. Everything else should function the same. Thank you for your help. I will try this and let you know how I get on. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1327633 Share on other sites More sharing options...
ben_1uk Posted November 6, 2012 Author Share Posted November 6, 2012 Hello QuickOldCar, It's been a very long time since I was on here last - work is very busy! I just wanted to let you know I have finally gotten round to trying the above code change and I'm happy to report that it worked. I haven't been able to test the system fully in as much as seeing if tickets will still go through the same process from POS to confirmation, but given how little the code has been changed, I don't see how it will stop working (fingers and toes crossed!). Thanks again for your help. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1390492 Share on other sites More sharing options...
ben_1uk Posted February 26, 2013 Author Share Posted February 26, 2013 Hi everyone, Sorry to kick an old thread back to life, but I was wondering is anybody can offer any assistance with a new requirement now being asked of me using the above criteria..? The ticket counter on the website has been removed completely by 'commenting out' the code as suggested by QuickOldCar, which has worked well. However, I now need the ticket counter to reappear when tickets reach a certain number to advertise that ticket sales are low for a particular venue - say for example, 30 tickets remaining. Can anyone offer any advice or a way to do this by adapting the above code? Many thanks in advance for any suggestions, Ben_1uk. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1415062 Share on other sites More sharing options...
Christian F. Posted February 26, 2013 Share Posted February 26, 2013 Just uncomment the code again, and wrap an IF block around it. Test the number of tickets, and if above your threshold execute the code that shows the counter. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1415065 Share on other sites More sharing options...
ben_1uk Posted February 26, 2013 Author Share Posted February 26, 2013 Just uncomment the code again, and wrap an IF block around it. Test the number of tickets, and if above your threshold execute the code that shows the counter. Hi Christian, Thanks for your prompt response. I'm not overly confident coding in PHP and would appreciate it if you could show me how to do what you have suggested using the necessary code. I did not code the original script and it's a little above my capability (for now!) to make any changes without being shown how. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1415067 Share on other sites More sharing options...
Christian F. Posted February 26, 2013 Share Posted February 26, 2013 Just about to hit the bed here, but if you check out the PHP manual page for IF you should find all the information you need: http://www.php.net/manual/en/control-structures.if.php Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1415209 Share on other sites More sharing options...
QuickOldCar Posted February 27, 2013 Share Posted February 27, 2013 (edited) Instead of the commented out line, place this there. The below code should show only when there are 1 to 29 tickets left. if($v['tickets_left'] < 30 && $v['tickets_left'] >= 1){ echo "<div class='tickets'>" . ($v['tickets_left'] < 30 ? "<span class='tickets_low'>" . escape($v['tickets_left']) . "</span>" : "" . escape($v['tickets_left']) . "") . " tickets left to buy for this match</div>"; } Edited February 27, 2013 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1415260 Share on other sites More sharing options...
ben_1uk Posted February 27, 2013 Author Share Posted February 27, 2013 Thanks again QuickOldCar! If I understand you correctly, you are effectively saying I should do something like this: if($v['tickets_left'] < 30 && $v['tickets_left'] >= 1){ echo "<div class='tickets'>" . ($v['tickets_left'] < 30 ? "<span class='tickets_low'>" . escape($v['tickets_left']) . "</span>" : "" . escape($v['tickets_left']) . "") . " tickets left to buy for this match</div>"; } if ($v['tickets_left'] > 0) { echo " <div class='tickets_buy'> <input type='hidden' name='venue[]' value='" . escape($v['id']) . "' /> Select how many tickets you wish to buy <select name='quantity[]' id='venue_" . escape($venuecount) . "' onchange='update_tickets()' onkeyup='update_tickets()'> <option value='0'>No tickets</option> <option value='1'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '1' ? " selected='selected'" : "") . ">1 ticket</option> " . ($v['tickets_left'] > 5 ? " <option value='2'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '2' ? " selected='selected'" : "") . ">2 tickets</option> <option value='3'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '3' ? " selected='selected'" : "") . ">3 tickets</option> <option value='4'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '4' ? " selected='selected'" : "") . ">4 tickets</option> <option value='5'" . (isset($_SESSION['tickets'][$v['id']]) && $_SESSION['tickets'][$v['id']] == '5' ? " selected='selected'" : "") . ">5 tickets</option>" : "") . " </select> <a href='#buy'>Confirm Ticket</a> </div> "; $venuecount++; } I don't think my attempt is quite right because I now have two IF commands and I'm not sure if I have enough curly brackets to wrap both of them..? Can you please advise? I think the above code is now saying: if tickets left is less than 30, but greater than 1, display "tickets_low". Therfore, if tickets remaining is higher than 30, the counter still won't show..? If the number of tickets left available is greater than 0, people have the option to buy tickets, which will still be handled by the existing code. Once again, thank you very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1415338 Share on other sites More sharing options...
Christian F. Posted February 27, 2013 Share Posted February 27, 2013 Yep, that is exactly what the code is saying. Also, the curly braces in the code you posted are matched. If not, PHP would throw a fatal error complaining about it. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1415342 Share on other sites More sharing options...
ben_1uk Posted February 27, 2013 Author Share Posted February 27, 2013 Yep, that is exactly what the code is saying. Also, the curly braces in the code you posted are matched. If not, PHP would throw a fatal error complaining about it. Are you saying the script will work before I start making any changes? I've had the misfortune of generating PHP errors before and the entire web page disappears Thanks again both. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1415367 Share on other sites More sharing options...
ben_1uk Posted March 5, 2013 Author Share Posted March 5, 2013 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1416732 Share on other sites More sharing options...
Christian F. Posted March 5, 2013 Share Posted March 5, 2013 Have you tried it? If so, did it work or not?<br />We cannot give you any guarantees that the code will work, as there are way too many factors involved. Not the least of them being the existing code you have. That said, the code looks right, and should work.<br /><br />If you get errors, investigate them and try to see if you can figure out why you get them. If you've tried, and still can't figure it out, then please post them here so that we can guide you on where to look. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1416736 Share on other sites More sharing options...
ben_1uk Posted March 5, 2013 Author Share Posted March 5, 2013 Have you tried it? If so, did it work or not?<br />We cannot give you any guarantees that the code will work, as there are way too many factors involved. Not the least of them being the existing code you have. That said, the code looks right, and should work.<br /><br />If you get errors, investigate them and try to see if you can figure out why you get them. If you've tried, and still can't figure it out, then please post them here so that we can guide you on where to look. Hi Christian, No, I haven't tried the code yet - I'm nervous to! I will try what you and the others have suggested above and let you know. I have a 'test' version of the website, which can only be accessed from my individual IP address so any changes I make will effectively be 'off-line'. Fingers crossed! Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1416749 Share on other sites More sharing options...
ben_1uk Posted March 5, 2013 Author Share Posted March 5, 2013 It works Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1416753 Share on other sites More sharing options...
ben_1uk Posted April 23, 2013 Author Share Posted April 23, 2013 Hello, When tickets for a venue sell out, I have set the code so it should generate a message to advise the public that tickets for that particular event are no longer available to buy. Here is the code: if (count($venues) == 0) { echo "<div class='error'>There are no more tickets available to buy</div>"; } else { echo " <form method='post' action='summary.php'>"; $venuecount = 0; foreach ($venues as $v) { echo "<div class='venue'> <div class='match_date'><b>Match Date:</b> " . date(ymd, $v['m_date']) . "</div> <h2>" . escape($v['venue_name']) . "</h2> <div class='venue_address'>" . nl2br(escape($v['venue_address'])) . "</div> <div class='tickets_container'>"; However, tickets for one of the venues have sold out, yet the message do not display??? What have I done wrong? Thanks, Ben_1uk Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1426124 Share on other sites More sharing options...
mac_gyver Posted April 23, 2013 Share Posted April 23, 2013 the line if (count($venues) == 0) { being true means that there are no venues found/defined/entered in the database, not that there are no tickets available for any specific venue. as you loop over each venue's data starting with the line foreach ($venues as $v) {, you would test the $v['tickets_left'] value and output whatever it is you want for the case where there are and are not any tickets left. since the code is already testing if ($v['tickets_left'] > 0) { ... code when there are tickets left ... } if what you are asking is to output a message when there are no tickets left, just an an else { ... code when there are no tickets left... } statement on the end of that if(){} statement. Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1426132 Share on other sites More sharing options...
ben_1uk Posted April 23, 2013 Author Share Posted April 23, 2013 the line if (count($venues) == 0) { being true means that there are no venues found/defined/entered in the database, not that there are no tickets available for any specific venue. as you loop over each venue's data starting with the line foreach ($venues as $v) {, you would test the $v['tickets_left'] value and output whatever it is you want for the case where there are and are not any tickets left. since the code is already testing if ($v['tickets_left'] > 0) { ... code when there are tickets left ... } if what you are asking is to output a message when there are no tickets left, just an an else { ... code when there are no tickets left... } statement on the end of that if(){} statement. Thanks Mac, Would you mind showing me what you mean? Thanks. Ben_1uk Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1426133 Share on other sites More sharing options...
mac_gyver Posted April 23, 2013 Share Posted April 23, 2013 if($v['tickets_left'] > 0){ ... code when there are tickets left ... // you already have this } else { // add this, right after the closing } of the existing if(){} statement ... code when there are no tickets left ... } Quote Link to comment https://forums.phpfreaks.com/topic/258752-php-code-help-needed/#findComment-1426135 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.