Jump to content

Помогите с условием


TemKa_SD
 Share

Recommended Posts

Здравствуйте. Не могу сообразить.

 

У меня есть 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

Как правильно сделать 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

Если у Вас в 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

  • Upvote 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...