Jump to content

Help needed


danmaxito

Recommended Posts

Hello PHP Freaks,

I have a MySQL database set up with a table that holds "Events". Using PHP, the "Events" are then shown on the webpage in thre *categories and sorted by date (not the date that the "Event" was created, but the date the the admin set for the "Event" to take place).

* the 3 categories are: "Upcoming Events", "Todays Events", and "Past Events".

When an "Event's" date is past the current date, then it gets puched to the "Past Events" Category etc.

Now the problem I am having, is: On the front end of the site, I want to only show the 2 most current "Events", in a way that they will update everytime, and will never show "Past Events". And the option to show more than 2 will be nice. It sounds so simple to do, yet I can't figure it out.... maybe I am not thinking right today.

Thanks in advance
Danmaxito
Link to comment
Share on other sites

[!--quoteo(post=358963:date=Mar 27 2006, 12:29 PM:name=Danmaxito)--][div class=\'quotetop\']QUOTE(Danmaxito @ Mar 27 2006, 12:29 PM) [snapback]358963[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hello PHP Freaks,

I have a MySQL database set up with a table that holds "Events". Using PHP, the "Events" are then shown on the webpage in thre *categories and sorted by date (not the date that the "Event" was created, but the date the the admin set for the "Event" to take place).

* the 3 categories are: "Upcoming Events", "Todays Events", and "Past Events".

When an "Event's" date is past the current date, then it gets puched to the "Past Events" Category etc.

Now the problem I am having, is: On the front end of the site, I want to only show the 2 most current "Events", in a way that they will update everytime, and will never show "Past Events". And the option to show more than 2 will be nice. It sounds so simple to do, yet I can't figure it out.... maybe I am not thinking right today.

Thanks in advance
Danmaxito
[/quote]

Past Events:
[code]SELECT * FROM Events WHERE event_date < CURDATE() ORDER BY event_date[/code]
Todays Events:
[code]SELECT * FROM Events WHERE event_date = CURDATE()[/code]
Upcoming Events:
[code]SELECT * FROM Events WHERE event_date > CURDATE() ORDER BY event_date[/code]

Your front page that only shows 2:
[code]SELECT * FROM Events WHERE event_date = CURDATE() LIMIT 2[/code]

I'm no expert, but that would be the right direction anyways....

Edit: Darn, i took so long to figure out your answer, that Barand beat me :)
Link to comment
Share on other sites

[code]$sql = "SELECT * FROM events
     WHERE eventdate >= CURDATE()
     ORDER BY eventdate
     LIMIT 2";

$res = mysql_query($sql) or die (mysql_error());

$events = array();
while ($row = mysql_fetch_assoc($res)) {

          // store event date in array
          $events[] = $row;
}[/code]

Now you can echo the details of either event wherever you want

eg (assuming you have a cols called eventdate and venue)

[code]echo $events[0]['eventdate'];    // echo eventdate field for 1st event
echo $events[1]['venue];    // echo venue field for 2nd event[/code]
Link to comment
Share on other sites

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.