Jump to content

Archived

This topic is now archived and is closed to further replies.

danmaxito

Help needed

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

Share this post


Link to post
Share on other sites
Do you mean

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

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
GREAT!!! Thanks.. Now that I have it limited to 2, what PHP code do I use to display the first "event" in one location of the front-end, and the second "event" on another location of the front-end.

THANKS A LOT GUYS!!!
Danmaxito

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.