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