sweetback Posted September 13, 2008 Share Posted September 13, 2008 Hello, I am new to php so I am sorry if this is an easy question. I am looking to make a little box on my site that will update itself based on the date. I run a group that meets on Sunday evening, and would like for this event box to update itself and show the event that will be coming up on Sunday. So, hypothetically, each Monday, it would update and show the next event (which would take place Sunday). Is there a way to do this with mysql and php? Thanks so much for any help you can give! Link to comment https://forums.phpfreaks.com/topic/124020-pull-mysql-value-based-on-date/ Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 Do you have anything set up in MySQL as of now? Link to comment https://forums.phpfreaks.com/topic/124020-pull-mysql-value-based-on-date/#findComment-640286 Share on other sites More sharing options...
sweetback Posted September 13, 2008 Author Share Posted September 13, 2008 I haven't set up the database for this yet... no. I have other databases, but nothing for this yet. Wasn't sure how to approach it. Link to comment https://forums.phpfreaks.com/topic/124020-pull-mysql-value-based-on-date/#findComment-640287 Share on other sites More sharing options...
sweetback Posted September 19, 2008 Author Share Posted September 19, 2008 anyone have any thoughts on this? Is it possible with php? Link to comment https://forums.phpfreaks.com/topic/124020-pull-mysql-value-based-on-date/#findComment-645371 Share on other sites More sharing options...
Stooney Posted September 19, 2008 Share Posted September 19, 2008 Here's how I'd probably do it. (Tested and working) <?php for($i=0; $i<=6; $i++){ if(date('l', mktime(0, 0, 0, date('m'), date('d')+$i, date('Y')))=='Sunday'){ $next_sunday=date('m-d-Y', mktime(0, 0, 0, date('m'), date('d')+$i, date('Y'))); } } echo 'Next Sunday\'s date is '.$next_sunday; ?> Link to comment https://forums.phpfreaks.com/topic/124020-pull-mysql-value-based-on-date/#findComment-645399 Share on other sites More sharing options...
sweetback Posted September 19, 2008 Author Share Posted September 19, 2008 Thanks Chris! That works really well! I really appreciate your help with this. So how would I then apply this to get the code to pull a value (in this case a text string of the upcoming event) that was associated with the upcoming Sunday. for instance... I would like to have box that says something like: THIS SUNDAY, and then below that, a string that would automatically update and show what the next event is. Link to comment https://forums.phpfreaks.com/topic/124020-pull-mysql-value-based-on-date/#findComment-645751 Share on other sites More sharing options...
discomatt Posted September 19, 2008 Share Posted September 19, 2008 Your best bet for this is to do everything purely in MySQL Set up your table with a `date` column of DATE type Then simply use a query like this SELECT `description` FROM `events` WHERE `date` BETWEEN (CURRENT_DATE - INTERVAL DAYOFWEEK(NOW())-2 DAY) AND (CURRENT_DATE + INTERVAL 8-DAYOFWEEK(NOW()) DAY); Which will columns where `date` is between the Monday and the Sunday of the current week. Link to comment https://forums.phpfreaks.com/topic/124020-pull-mysql-value-based-on-date/#findComment-645809 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.