bob_the _builder Posted May 11, 2007 Share Posted May 11, 2007 Hi, I have a query that shows all appointments of a chosen day using the following format: $eventid=2007-05-21 WHERE starttime LIKE '".$eventid."%' I have a calendar and am trying to make it show all records for the selected month, or display all records from a specific day if a day is selected from the calendar. So far I have it where I can show records from specific day, but want selected months records as default. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/ Share on other sites More sharing options...
MadTechie Posted May 11, 2007 Share Posted May 11, 2007 what type of field is starttime ? Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250955 Share on other sites More sharing options...
MadTechie Posted May 11, 2007 Share Posted May 11, 2007 EDIT if the field is a date field you could try WHERE MONTH(starttime) = 21 AND DAYOFMONTH(starttime) = 5 AND YEAR(starttime) = 2007 theirs better ways but still just an example! Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250960 Share on other sites More sharing options...
bob_the _builder Posted May 11, 2007 Author Share Posted May 11, 2007 Hi, Its stored as "datetime" Im looking more for an if statment I think. if(isset($eventid)){ $eventid = 2007-05-21 }else{ $eventid = selected_month } Not sure really, trying to keep it simple. Just not sure how to grab all records = to 5th month or 6th month. The variable passed is "2007-05-21" maybe use explode and the date parts? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250963 Share on other sites More sharing options...
MadTechie Posted May 11, 2007 Share Posted May 11, 2007 i think its better to get it done in mySQL using the interval may help ie WHERE 'starttime' > DATE_ADD(2007-05-21, INTERVAL 1 MONTH); try looking here Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250967 Share on other sites More sharing options...
bob_the _builder Posted May 11, 2007 Author Share Posted May 11, 2007 When a day is selected from the calendar with the following link, I pass the variable ?day <a href=calendar.php?day&add='.$_GET['add'].'&eventid='.$linkdate.'>'.$day.'</a> I was thinking I could maybe alter the variable $eventid if isset($_GET['day']) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250970 Share on other sites More sharing options...
bob_the _builder Posted May 11, 2007 Author Share Posted May 11, 2007 is the following used to grab records for that month? SELECT MONTH('1998-02-03'); -> 2 I could maybe switch the query if isset($_GET['day'])? Altho I havnt managed to get SELECT MONTH('1998-02-03'); -> 2 working in my query. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250980 Share on other sites More sharing options...
MadTechie Posted May 11, 2007 Share Posted May 11, 2007 close its more like SELECT * FROM table WHERE MONTH(starttime) = {$_GET['day']}"; Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250984 Share on other sites More sharing options...
bob_the _builder Posted May 12, 2007 Author Share Posted May 12, 2007 Hmm Tried a few ways, no success: $eventid=2007-05-21 $sql = mysql_query("SELECT id, firstname, lastname, phone, cellphone, email, MONTH(starttime) -> 2, finishtime, event FROM calendar WHERE starttime LIKE '".$eventid."%' ORDER BY starttime ASC"); Trying to pull all records for the 5th month. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250995 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 erm.. whats MONTH(starttime) -> 2 try <?php $eventid=2007-05-21; //only uses the 05 $sql = mysql_query("SELECT id, firstname, lastname, phone, cellphone, email, finishtime, event FROM calendar WHERE MONTH(starttime) = MONTH($eventid), ORDER BY starttime ASC"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-250999 Share on other sites More sharing options...
bob_the _builder Posted May 12, 2007 Author Share Posted May 12, 2007 That was from the manual I have tried a few ways with no success. Brings back no matches: $sql = mysql_query("SELECT id, firstname, lastname, phone, cellphone, email, starttime, finishtime, event FROM calendar WHERE MONTH(starttime) LIKE 'MONTH(".$eventid.")%'"); Must be close, all makes sence. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-251008 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 can you try the example i posted last please! Quote Link to comment https://forums.phpfreaks.com/topic/51002-date/#findComment-251270 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.