Jump to content

month offset using get month


BandonRandon

Recommended Posts

Hello,

 

A while back i posted this post http://www.phpfreaks.com/forums/index.php/topic,232640.msg1084366.html on trying to get all the events for a given month it worked fine for a month now there seams to be a problem with the offset. It will get the first months(or current month) but if you go to next or previous the offset breaks.  What i mean by breaks it the next link will link to a month with no events then if you click previous that month's events will show up on the current month page. If you click previous when on the current month it will show the current months events on the previous page.

 

Here is the sql querry and the month offset:

if(isset($get_month))
{
    $startMonthOffset=-1+$get_month-1;
    $endMonthOffset=0+$get_month-1;
}
else 
{
    $startMonthOffset=-1;
    $endMonthOffset=0;
}


$query="SELECT *
FROM `events`
WHERE `event_type` = '0'
AND `start_date` BETWEEN
(STR_TO_DATE(((PERIOD_ADD( EXTRACT(YEAR_MONTH FROM ADDDATE(SYSDATE(),INTERVAL +$startMonthOffset MONTH) ) , 1 ) *100) +1), '%Y%m%d' ))
AND
(STR_TO_DATE(((PERIOD_ADD( EXTRACT(YEAR_MONTH FROM ADDDATE(SYSDATE(),INTERVAL +$endMonthOffset MONTH) ) , 1 ) *100) +1), '%Y%m%d' ))
ORDER BY `start_date` ASC";

 

here is the value of $get_month

if(isset ($get_month)){
$display_month = $get_month;
$previous_m = $get_month-1;
$next_m = $get_month+1;
}
//else show currnet month
else{
$display_month = $month;
$previous_m = $month-1;
$next_m = $month+1;
}

 

any help would be great. Also i'm not sure if this is a PHP or sql issue but to me it seams more like a sql one.

 

Thanks,

Brandon

Link to comment
https://forums.phpfreaks.com/topic/146750-month-offset-using-get-month/
Share on other sites

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.