Members: 296  •  Posts: 13545  •  Topics: 893  •  Please welcome capelu, our newest member.
Please login or register.

Login with username, password and session length
 

News:

Welcome To Graphics Mayhem

collapse

Author Topic: Need PHP help  (Read 90 times)

0 Members and 1 Guest are viewing this topic.

Shortie

  • Administrator
  • Expert
  • Offline
  • Posts: 3836
  • The Ultimate Boss
  • OS:
  • Windows 7/Server 2008 R2
  • Browser:
  • Firefox 3.5.5
Need PHP help
« on: November 13, 2009, 05:51:46 AM »
    Okay

    need to translate this into PHP anyone care to lend a hand

    Code: [Select]
    IF (statement1) or (statement2) or (statement3 and statement4) or (statement5)
    do something
    ELSE
    Go way

    Cheers Shortie
    Thank You, "Guest" For Reading My Post.

    SoLoGHoST

    • SMF MOD Expert!
    • SoLoGHoSt
    • Connoisseur
    • Online
    • Posts: 2173
    • OS:
    • Windows Vista/Server 2008
    • Browser:
    • Firefox 3.0.15
    Re: Need PHP help
    « Reply #1 on: November 13, 2009, 07:18:10 AM »
      Well, not really sure what the statements are supposed to represent.  I changed them to php variables, but if this isn't the case, you can always change them.

      Code: [Select]
      if ($statement1 || $statement2 || $statement5 || ($statement3 && $statement4))
      {
      // do something
      }
      else
      {
      redirectexit(); // Takes them to the home page...
      // other options.
      // fatal_error('Error', false); <-- This will give an error message
      // exit; <-- This will exit execution of the rest of the code.
      }

      Shortie

      • Administrator
      • Expert
      • Offline
      • Posts: 3836
      • The Ultimate Boss
      • OS:
      • Windows 7/Server 2008 R2
      • Browser:
      • Firefox 3.5.5
      Re: Need PHP help
      « Reply #2 on: November 13, 2009, 07:38:55 AM »
        Ah

        Double Blips and surrounded by brackets

        If each statement is a context

        Like the one I have just changed to your style

        Code: [Select]
        ($context['in_maintenance'] && $context['user']['is_admin'])
        I just replace the complete $Statement with the above inc brackets

        e.g

        Code: [Select]
        if (($context['in_maintenance'] && $context['user']['is_admin']) || (!empty($context['user']['avatar'])) || (!empty($context['open_mod_reports']) && $context['show_open_reports']))
        Just making sure the Brackets etc are in the right place also the final is a lot longer but it is the principle I am after

        Cheers
        Dude
        « Last Edit: November 13, 2009, 07:43:16 AM by Shortie »
        Thank You, "Guest" For Reading My Post.

        SoLoGHoST

        • SMF MOD Expert!
        • SoLoGHoSt
        • Connoisseur
        • Online
        • Posts: 2173
        • OS:
        • Windows Vista/Server 2008
        • Browser:
        • Firefox 3.0.15
        Re: Need PHP help
        « Reply #3 on: November 13, 2009, 08:08:16 AM »
          Ok, so according to your if statement, there are 3 conditions in which this will be true:

          1st condition:  $context['in_maintenance'] && $context['user']['is_admin']
          OR
          2nd condition:  !empty($context['user']['avatar'])
          OR
          3rd condition: !empty($context['open_mod_reports']) && $context['show_open_reports']

          if this is the correct conditions, than yep, looks good.  Just removed the ( and ) from around the !empty($context['user']['avatar']), which is not a big deal, just not needed in here:

          Code: [Select]
          if (($context['in_maintenance'] && $context['user']['is_admin']) || !empty($context['user']['avatar']) || (!empty($context['open_mod_reports']) && $context['show_open_reports']))
          FYI:  A few Basic PHP Operators, when working with if statements, that can be used:
          Code: [Select]
          AND: &&
          OR: ||
          Is Equal to: ==
          Is Not Equal to: !=
          Is Less than: <
          Is Less than or equal to: <=
          Is Greater than: >
          Is Greater than or equal to: >=
          Not: !

          Also Shortie, if this is going to be a very long if statement, may be a better idea to set variables for each statement/condition, for example:

          Code: [Select]
          $statement1 = $context['in_maintenance'] && $context['user']['is_admin'] ? true : false;
          $statement2 = !empty($context['open_mod_reports']) && $context['show_open_reports'] ? true : false;

          // Than the if statement can change to this:

          if ($statement1 || !empty($context['user']['avatar']) || $statement2)

          So this approach makes it more manageable.

          Cheers :)

          « Last Edit: November 13, 2009, 08:31:34 AM by SoLoGHoST »

          Shortie

          • Administrator
          • Expert
          • Offline
          • Posts: 3836
          • The Ultimate Boss
          • OS:
          • Windows 7/Server 2008 R2
          • Browser:
          • Firefox 3.5.5
          Re: Need PHP help
          « Reply #4 on: November 13, 2009, 08:31:10 AM »
            Cool gives me starting block

            Cheers dude

            Shortie
            Thank You, "Guest" For Reading My Post.

            SoLoGHoST

            • SMF MOD Expert!
            • SoLoGHoSt
            • Connoisseur
            • Online
            • Posts: 2173
            • OS:
            • Windows Vista/Server 2008
            • Browser:
            • Firefox 3.0.15
            Re: Need PHP help
            « Reply #5 on: November 13, 2009, 08:34:35 AM »
              Sure thing :thumbsup:
               


              Search


              Latest Activity.
              Help Required - 3d Creation Practice by SoLoGHoST
              [Today at 06:14:12 PM]


              December's Logo Challenge "Up Top" (2009)... by Shortie
              [Today at 04:46:05 PM]


              how to install xtra icons in posting and top header with new buttons. by live627
              [Today at 04:18:13 PM]


              Pixel Perfected for SMF 2 RC2 by Shortie
              [Today at 04:11:38 PM]


              Logo/Icon request by spoogs
              [Today at 02:38:22 PM]


              help in background by SoLoGHoST
              [Today at 01:55:03 PM]


              Need badges please by DaianeRocha
              [Today at 08:59:54 AM]


              Graphics Mayhem Christmas Wallpapers by Shortie
              [Today at 08:53:49 AM]


              Novembers Graphics Mayhem Wallpaper by DMHolt57
              [Yesterday at 11:52:28 PM]


              November's Logo Challenge "Up Top" (2009)... by NerdBoy
              [Yesterday at 08:37:01 PM]


              Installation by CarpeDiemTG
              [Yesterday at 04:48:22 PM]



              Page created in 0.088 seconds with 22 queries.