ben_1uk Posted April 24, 2013 Author Share Posted April 24, 2013 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'>"; 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++; } 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>"; } } Sorry Mac, I have tried what you have said but cannot get it to work. I have included the original code in it's entirity before I starting changing it. Can you offer any further guidance? Thanks. Quote Link to comment Share on other sites More sharing options...
ben_1uk Posted April 25, 2013 Author Share Posted April 25, 2013 (edited) Hi, I have had another look at the code this morning and instead of adding an 'else' statement, I have added another 'if' statement at the end of the existing 'if' statement (I couldn't get an 'else' statement to work?): if ($v['tickets_left'] < 1) { echo " <div class='error'>There are no more tickets available to buy</div>"; } I have tested the above code using a 'test' site I have set-up which still looks at live data in the SQL db but does not affect the live site. I have attached an image showing what the above code outputs. It appears to work, unless there is something I have done above that is not 'correct' or working to best practice..? Edited April 25, 2013 by ben_1uk Quote Link to comment Share on other sites More sharing options...
ben_1uk Posted April 26, 2013 Author Share Posted April 26, 2013 Can someone please tell me if it's ok to have to 'if' statements one after the other as shown in the above code samples? I have attempted to research this on the Internet, but I cannot find a 'layman's' explanation! Thanks in advance. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 27, 2013 Share Posted April 27, 2013 you can do anything you want in a programming language if it produces the result you want. the creative part of programming is to get a computer to do what you want, where you want it to be at. if you want to display a message that there are no tickets left, you write the logic to test for that condition and produce the message you want at the point where you have that data available and at the point where you want that message to be output at. Quote Link to comment Share on other sites More sharing options...
ben_1uk Posted April 29, 2013 Author Share Posted April 29, 2013 you can do anything you want in a programming language if it produces the result you want. the creative part of programming is to get a computer to do what you want, where you want it to be at. if you want to display a message that there are no tickets left, you write the logic to test for that condition and produce the message you want at the point where you have that data available and at the point where you want that message to be output at. In that case, I don't think there is anything wrong with what I have done. I have already tested the code and it produces the message where I want it to appear. I just always worry about unforseen 'knock-on' effects - especially as the original code is not my own. Quote Link to comment 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.