Jump to content


Photo

Help needed


  • Please log in to reply
6 replies to this topic

#1 danmaxito

danmaxito
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 27 March 2006 - 05:29 PM

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

#2 danmaxito

danmaxito
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 28 March 2006 - 04:59 PM

Anyone?

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 March 2006 - 05:42 PM

Do you mean

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 28 March 2006 - 05:46 PM

[!--quoteo(post=358963:date=Mar 27 2006, 12:29 PM:name=Danmaxito)--][div class=\'quotetop\']QUOTE(Danmaxito @ Mar 27 2006, 12:29 PM) View Post[/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:
SELECT * FROM Events WHERE event_date < CURDATE() ORDER BY event_date
Todays Events:
SELECT * FROM Events WHERE event_date = CURDATE()
Upcoming Events:
SELECT * FROM Events WHERE event_date > CURDATE() ORDER BY event_date

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

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 :)

#5 danmaxito

danmaxito
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 29 March 2006 - 05:35 AM

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

#6 danmaxito

danmaxito
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 29 March 2006 - 09:22 PM

is this easy to do?

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 29 March 2006 - 10:36 PM

$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;
}

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

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

echo $events[0]['eventdate'];    // echo eventdate field for 1st event
echo $events[1]['venue];    // echo venue field for 2nd event

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users