TemKa_SD Posted November 14, 2018 Share Posted November 14, 2018 Здравствуйте. Не могу сообразить. У меня есть year и month в разных полях, вот это рабочий код для month, мне нужно добавить еще для года так же. Если выбран только месяц, отображать текущий год и выбранный месяц.Если выбран только год, отображать текущий месяц и выбранный год.Если выбран и месяц и год, отображать и месяц и год. Такие же условия должны быть? if ( isset( \IPS\Request::i()->month ) and isset( $months[ \IPS\Request::i()->month ] ) ) { $sqlCurrentDate = " AND year='" . $yearNow . "' AND month='" . $months[ \IPS\Request::i()->month ] . "' "; } else if ( isset( $year ) AND isset( $month ) ) { \IPS\Request::i()->month = $monthNow; \IPS\Request::i()->year = $yearNow; $sqlCurrentDate = " AND year='" . $yearNow . "' AND month='" . $monthNow . "' "; } Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 14, 2018 Author Share Posted November 14, 2018 Как правильно сделать 3 условие? // Если выбран только месяц. if ( isset( \IPS\Request::i()->month ) and isset( $months[ \IPS\Request::i()->month ] ) ) { \IPS\Request::i()->year = $yearNow; $sqlCurrentDate = " AND year='" . $yearNow . "' AND month='" . $months[ \IPS\Request::i()->month ] . "' "; } // Если выбран только год. else if ( isset( \IPS\Request::i()->year ) and isset( $years[ \IPS\Request::i()->year ] ) ) { \IPS\Request::i()->month = $monthNow; $sqlCurrentDate = " AND month='" . $monthNow . "' AND year='" . $years[ \IPS\Request::i()->year ] . "' "; } // Если выбран и месяц и год. else if ( ) { } // Если ничего не выбрано, текущие год и месяц. else if ( isset( $year ) AND isset( $month ) ) { \IPS\Request::i()->month = $monthNow; \IPS\Request::i()->year = $yearNow; $sqlCurrentDate = " AND year='" . $yearNow . "' AND month='" . $monthNow . "' "; } Link to comment Share on other sites More sharing options...
newbie Posted November 14, 2018 Share Posted November 14, 2018 Если у Вас в WHERE есть и год и месяц, то смысл городить огород с if/else \IPS\Request::i()->month = isset($months[\IPS\Request::i()->month]) ? $months[\IPS\Request::i()->month] : $monthNow; \IPS\Request::i()->year = isset($years[\IPS\Request::i()->year]) ? $years[\IPS\Request::i()->year] : $yearNow; $sqlCurrentDate = здесь уже используете \IPS\Request::i()->month и \IPS\Request::i()->year 1 Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 14, 2018 Author Share Posted November 14, 2018 Спасибо, всё супер. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now