Page 1 of 1
comparing two values doesn't seem to work
Posted: Wed Jan 19, 2011 12:02 pm
by someguyhere
I've used echo elsewhere in this script to double check the values being compared, and they both appear to contain the same value (2011-01 in this case)
Code: Select all
if(date('Y-m') == $current_page_year . '-' . $current_page_month){
$upcoming_events_start = $current_page_year . '-' . $current_page_month . '-' . date('d');
$upcoming_events_end = date('Y') . '-' . date('m') . '-31';
echo "success";
}
What am I doing wrong here?
Re: comparing two values doesn't seem to work
Posted: Wed Jan 19, 2011 12:09 pm
by Jonah Bron
I would compare them a bit differently.
Code: Select all
if (date('Y') == $current_page_year && date('m') == $current_page_month) {
If that doesn't work, try this for debugging:
Code: Select all
echo (date('Y') == $current_page_year && date('m') == $current_page_month);
Re: comparing two values doesn't seem to work
Posted: Wed Jan 19, 2011 3:51 pm
by someguyhere
Ok, tried that...it didn't work, so I echoed the statement, which returned 1. I assume that means that the statement is true, so maybe I have something wrong with how my if/else statements are nested. Is there something wrong here?
Code: Select all
if($current_page == "http://domain.com/calendar/"){
$upcoming_events_start = date('Y-m-d');
$upcoming_events_end = date('Y') . '-' . date('m') . '-31';
}
if(date('Y') == $current_page_year && date('m') == $current_page_month){
$upcoming_events_start = $current_page_year . '-' . $current_page_month . '-' . date('d');
$upcoming_events_end = date('Y') . '-' . date('m') . '-31';
}
else{
$current_page_year = substr( $current_page, strrpos( $current_page, '&yr=' )+4 );
$upcoming_events_start = $current_page_year . '-' . $current_page_month . '-01';
$upcoming_events_end = $current_page_year . '-' . $current_page_month . '-31';
}
Re: comparing two values doesn't seem to work
Posted: Wed Jan 19, 2011 3:53 pm
by Jonah Bron
I don't see anything wrong, but then again, I don't know what it's supposed to do. Try echoing something random inside of the problematic if statement, just to make sure.
Re: comparing two values doesn't seem to work
Posted: Wed Jan 19, 2011 4:16 pm
by someguyhere
The variables in the 2nd if statement were being overwritten by the else statement for some reason. I solved it by just declaring the variables to begin with, followed by the if statements, which will change the variables if needed.
I don't know if this is the *correct* solution, but it works
As such:
Code: Select all
$current_page_year = substr( $current_page, strrpos( $current_page, '&yr=' )+4 );
$upcoming_events_start = $current_page_year . '-' . $current_page_month . '-01';
$upcoming_events_end = $current_page_year . '-' . $current_page_month . '-31';
if($current_page == "http://domain.com/calendar/"){
$upcoming_events_start = date('Y-m-d');
$upcoming_events_end = date('Y') . '-' . date('m') . '-31';
}
if(date('Y') == $current_page_year && date('m') == $current_page_month){
$upcoming_events_start = $current_page_year . '-' . $current_page_month . '-' . date('d');
$upcoming_events_end = date('Y') . '-' . date('m') . '-31';
}