treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Need to change when gig list deletes shows

  • I am using Chris' Best Band Site for our schedule page. See it here

    Problem is that shows are auto deleting on the morning of the event. I need it to delete a couple of days later, or at least at the end of the day so that attendees can look up the location all day.
  • Do you have the SQL code it is using to call the data from the database?

    I'm guessing there will be a statement that says something like "SELECT * FROM Events WHERE EventDate > NOW()". JUst change the ">" to ">=".

  • Thanks TT_Mark. Here it is.

    <?php

    /* build output */
    $query = 'SELECT show_id, date_starts, stime, venue, url, city, state,
    DATE_FORMAT(date_starts,\'%b %e\') as ds
    FROM shows
    WHERE date_starts >= NOW()
    ORDER BY date_starts ASC';
    $result = mysql_query($query,$DATABASE_LINK) or die(mysql_error().': '.$query);
    if(mysql_num_rows($result))
    {
    //heading


    //for every show date
    while($row = mysql_fetch_assoc($result))
    {
    //reset vars
    $address = $dates = $event_venue = '';

    //start row
    $table.= '<div class="show-row" id="show-row-'.$row['show_id'].'">';

    //show dates
    //$dates = $row['ds'].($row['de'] && $row['de']!= $row['ds'] ? ' - '.$row['de'] : '');
    $dates = $row['ds'];
    $table.= ' <div class="show-row-dates" id="date-'.$row['show_id'].'">'.$dates.'</div>';

    //show event/venue
    if($row['url']) { $event_venue.='<a href="'.$row['url'].'">'; }
    //if($row['event']) { $event_venue.= $row['event']; }
    //if($row['event'] && $row['venue']) { echo '<br />'; }
    if($row['venue']) { $event_venue.= $row['venue']; }
    if($row['url']) { $event_venue.='</a>'; }
    $table.= ' <div class="show-row-event-venue" id="venue-'.$row['show_id'].'">'.$event_venue.'</div>';

    //build & show address
    //if($row['address']) { $address.= $row['address'].'<br />'; }
    if($row['city']) { $address.= $row['city']; }
    if($row['city'] && $row['state']) { $address.= ', '; }
    if($row['state']) { $address.= $row['state']; }
    //if($row['zip']) { $address.= ' '.$row['zip']; }
    $table.= ' <div class="show-row-address" id="address-'.$row['show_id'].'">'.$address.'</div>';

    //show time
    $table.= ' <div class="show-row-time" id="stime-'.$row['show_id'].'">'.($row['stime'] ? $row['stime'] : '&nbsp').'</div>';

    //admin?
    if($_SESSION['admin'])
    {
    $table.= '<div class="show-row-admin">
    <a href="update.php?'.$row['show_id'].'" rel="moodalbox 400 400" class="edit-button">Edit</a>
    <a href="javascript:;" onclick="delete_event('.$row['show_id'].');" class="delete-button">Delete</a>
    </div>';
    }

    //end row
    $table.= '<div class="clear"></div>';
    $table.= '</div>';
    }
    }
    else
    {
    //output general message
    $table = '<p>Sorry! There is no show information available at this time. Check back soon!</p>';
    }

    ?>
  • Hmm...that SQL statement looks right, did you change it to that or was it set to that already?

     $query = 'SELECT show_id, date_starts, stime, venue, url, city, state,
    DATE_FORMAT(date_starts,\'%b %e\') as ds
    FROM shows
    WHERE date_starts >= NOW()
    ORDER BY date_starts ASC';


    This is the important bit, basically says pick anything where date is either today or in the future
  • I didn't change it. Shows are still being deleted at the beginning of the day. Can I change that code somehow to tell it to delete a few days after the event?
  • If you can add one day to the query it would delete them the day after. My SQL knowledge suck but it should be doable by replacing the WHERE:

    WHERE date_starts >= DATE_ADD(NOW(), INTERVAL 1 DAY)


    This was modified from: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_adddate

    It might work :-p.
  • Thanks all. Added a "-" to the 1 and it worked.
  • I was close!! Glad it helped...