Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-05-2011, 08:28 PM   PM User | #1
nick.elliott10
New Coder

 
Join Date: Oct 2011
Location: Cambridgeshire, UK
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
nick.elliott10 is an unknown quantity at this point
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 04:14 PM.. Reason: Incorrect Code
nick.elliott10 is offline   Reply With Quote
Old 10-05-2011, 09:43 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 10-06-2011, 04:31 PM   PM User | #3
nick.elliott10
New Coder

 
Join Date: Oct 2011
Location: Cambridgeshire, UK
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
nick.elliott10 is an unknown quantity at this point
Thank you for your help Old Pedant! It is much appreciated.
nick.elliott10 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:04 PM.


Advertisement
Log in to turn off these ads.