doubledee Posted October 3, 2011 Share Posted October 3, 2011 I want to only show Events that occur in October. I'm a little unsure how to modify this code... // Build query. $q = 'SELECT name, location, dateandtime FROM topic WHERE dateandtime=?'; // Prepare statement. $stmt = mysqli_prepare($dbc, $q); // Bind variable. mysqli_stmt_bind_param($stmt, 'i', $id); Is there a PHP function that I should use? Or do I just use a conditional? And not sure if I even need a bound variable here. Debbie Quote Link to comment Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 You dont need to bind a variable for this. Correction, you CAN if you want to change the month that will be displayed You can use straight mysql MONTH() Something like, SELECT `name` FROM `table` WHERE MONTH(`datetime`) = 10 Quote Link to comment Share on other sites More sharing options...
doubledee Posted October 3, 2011 Author Share Posted October 3, 2011 You dont need to bind a variable for this. Correction, you CAN if you want to change the month that will be displayed You can use straight mysql MONTH() Something like, SELECT `name` FROM `table` WHERE MONTH(`datetime`) = 10 Is there a way to make it more Englishy, like WHERE dateandtime = October or since we are discussing things... Show me all Events that are past today but no more than 45 day in the future. Debbie Quote Link to comment Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 More englishy you could use MONTHNAME(), info can be found on the same link. This should do what you need for the 45 day thing.. Its pretty self explanatory WHERE `datetime` BETWEEN NOW() AND DATE_ADD(NOW(),INTERVAL 45 DAY) Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 3, 2011 Share Posted October 3, 2011 One word of caution to what Buddski has suggested. Using WHERE MONTH(`datetime`) = 10 or the MONTHNAME() alternative will return any record that are in the specified month - regardless of year. I have seen very few - valid - implementations - that want to see all the records for a particular month across years. So, you likely need to add a year parameter to that WHERE clause. Quote Link to comment 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.