Jump to content

Recommended Posts

Hi everyone,

 

I hope you can help me.

 

I am working on a Website at present whereby I am advertising the number of available tickets left for an event. However, I now want to remove this feature from the site, but because I myself did not code the site initially, I'm not sure what part of the code needs to be removed.

 

I have included a copy of the code below:

 

	$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>
			[color=red][b]<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>";[/b][/color]

		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>

 

I have highlighted the code I understand needs to be changed, but I'm not overly familiar with this type of coding and do not want to screw up how the rest of the site works! I would really appreciate somebodys help on this!

 

Many thanks in advance,

BB2011

Link to comment
https://forums.phpfreaks.com/topic/227150-php-novice-needs-help/
Share on other sites

No I haven't - I worried about rendering the site useless! The problem I have is although I understand a little bit of the code, I'm not 100% sure what the highlighted code is doing.

 

Could someone translate the code for me? That way, I might have a better understanding of whether removing this section of code will help or not.

 

Thanks,

 

BB2011

Does anyone know what the above highlighted code is doing?

 

In theory, I can download the tickets.php file that exists on the server so I have a failsafe should removing the bit of code I think will remove the number of tickets left displayed on the web page doesn't actually work and has some sort of bizarre side effect!

 

If the changes I make don't work, I can just upload the original file again to replace the file I have changed and I shouldn't have any problems - should I?

 if (count($venues) == 0) {

 

A very simple way is modifiying that if because it governs if there are tickets or not.

 

You can simply do for now making that line always false (0).

 

That will be always false, this will give the error code. Thought i think you can code a better solution using a constant and explaining it (for example, for other person like you that comes later to modify the code).

 

 

 

  

#  true to set tickets sell active
define("TICKETS_STATE",     false);

   if (TICKETS_STATE and count($venues) == 0) {
      echo "<div class='error'>There are no more tickets available to buy</div>";
   }   
   elseif(TICKETS_STATE){
            # put here that code
    }
    # these else says a error that tells that tickets selling is off
   else {
      echo "<div class='error'>Tickets off</div>";
}

 

I have tried modifying the code as suggested above, but it has not made any difference.

 

I have also tried changing the code as follows:

 

if (count($venues) == 100) {
	echo "<div class='error'>Due to Internet traffic, ticket counter has been disabled</div>";

 

This hasn't worked either? Problem I have is because I didn't programme this originally, I'm struggling to get my head round how it works. I thought the change I made above would have worked, but it hasn't.

 

Can anybody else shed some light? I really need some help!

 

Thanks,

 

BB2011

 

Could you post the full page?  If there is nothing in there other than the ticket counter you should be able to get away with changing your

if (count($venues) == 100) {
      echo "<div class='error'>Due to Internet traffic, ticket counter has been disabled</div>";

to

 echo "<div class='error'>Due to Internet traffic, ticket counter has been disabled</div>";
die

 

however if there are, as I suspect, other things going on, then it will need some minor surgery.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.