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
https://forums.phpfreaks.com/topic/248315-show-events-for-october/
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

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.