Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2011
    Location
    Cambridgeshire, UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Forecoming Events Script

    To fellow coders,

    I am fairly new to coding in PHP and am working on a script to display forthcoming events on a website. I have got the code working so that it display all of the events from the database table, however when the event has past I want that event to disappear off the webpage so new events can appear.

    Any help will be appreciated.

    My current code is: -

    PHP Code:
    <?php
    include("includes/db/connect.php");
                                                        
    $sql "SELECT * FROM `events` WHERE active=1 AND eventDate > NOW() LIMIT 5";

    $result mysql_query($sql) or die(mysql_error());
    while(
    $row mysql_fetch_array($result))
    {
      echo 
    $row['eventName'];
      echo 
    "<br />";
      echo 
    $row['eventDate'];
      echo 
    "<br />";
      echo 
    $row['eventDescription'];                                  
      echo 
    "<br />";
      echo 
    "<br />";                                  
    }

    mysql_close();
    ?>
    Thank you for your help in advance.
    Last edited by nick.elliott10; 10-06-2011 at 05:14 PM. Reason: Incorrect Code

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    Code:
    $sql = "SELECT * FROM news 
            WHERE archive=1 
            AND newsTimeStamp > NOW()
            ORDER BY newsTimestamp DESC 
            LIMIT 3";
    This assumes that your newsTimeStamp field really is a TIMESTAMP or DATETIME field and not an INT field that hold a Unix time.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Oct 2011
    Location
    Cambridgeshire, UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your help Old Pedant! It is much appreciated.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •