Jump to content

Recommended Posts

Is there a way that I can retrieve all the events from a the current month with an SQL query?  I have tried a couple query and it has returned nothing.  I didn't know if I could use the Mysql MONTH() function or something liek that.  Here is how I have tried to do it so far:

 

<?php
//todays month
$m = date('m');

$query = "SELECT id FROM events WHERE date LIKE '____/" . $m . "/__' ORDER BY date";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))	
{
$id[] = $row['id'];
}
?>

 

I am retrieving the this for a calendar that I am linking the days to events.  If anyone has doen this or knows of a good tutorial that would be great.  I am using the calendar written by Kevin Devens here :http://keithdevens.com/software/php_calendar

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/105816-solved-query-syntax/
Share on other sites

If there is more than a single year's data

<?php

//todays month
$m = date('n');
$y = date('Y');

$query = "SELECT id FROM events 
		WHERE YEAR(date) = $y
		AND MONTH(date) = $m
		ORDER BY date";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))	
{
$id[] = $row['id'];
}
?>

Link to comment
https://forums.phpfreaks.com/topic/105816-solved-query-syntax/#findComment-542315
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.