danmaxito Posted March 27, 2006 Share Posted March 27, 2006 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 advanceDanmaxito Quote Link to comment https://forums.phpfreaks.com/topic/5944-help-needed/ Share on other sites More sharing options...
danmaxito Posted March 28, 2006 Author Share Posted March 28, 2006 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/5944-help-needed/#findComment-21649 Share on other sites More sharing options...
Barand Posted March 28, 2006 Share Posted March 28, 2006 Do you mean[code]SELECT * FROM events WHERE eventdate >= CURDATE() ORDER BY eventdateLIMIT 2;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5944-help-needed/#findComment-21661 Share on other sites More sharing options...
lead2gold Posted March 28, 2006 Share Posted March 28, 2006 [!--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 advanceDanmaxito[/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 :) Quote Link to comment https://forums.phpfreaks.com/topic/5944-help-needed/#findComment-21664 Share on other sites More sharing options...
danmaxito Posted March 29, 2006 Author Share Posted March 29, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/5944-help-needed/#findComment-21846 Share on other sites More sharing options...
danmaxito Posted March 29, 2006 Author Share Posted March 29, 2006 is this easy to do? Quote Link to comment https://forums.phpfreaks.com/topic/5944-help-needed/#findComment-22107 Share on other sites More sharing options...
Barand Posted March 29, 2006 Share Posted March 29, 2006 [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 eventecho $events[1]['venue]; // echo venue field for 2nd event[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5944-help-needed/#findComment-22120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.