Jump to content

Show Events for October


doubledee

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.