nested if's

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JRough

    nested if's

    I got lost on formatting the nested if/else's on the bottom of the
    file right up the last else/if there seems to be a stray bracket. I'm
    trying to line up the brackets so I can read it. Is it okay to split
    a long line setting a variable on two lines at the equals sign? That
    is so you can read it in google groups.

    <?
    //Send payement advices
    $TPL_auction_id = $auction_id;
    $user_id=$userr ec["id"];
    if(!$sessionVar s["SELL_actio n"]) {
    include "header.php ";
    }
    if($FEE>0) {
    if($SETTINGS["invoicing"] == 'y') {
    if(!$sessionVar s["SELL_actio n"]=="edit") {
    include phpa_include("t emplate_menu_ph p.html");
    include phpa_include("t emplate_sell_re sult_php.html") ;
    } else {
    $auction_url =
    $SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;
    if($sessionVars["SELL_actio n"]=="edit") {
    unset($_SESSION["sessionVar s"]);
    unset($_SESSION["RELISTEDAUCTIO N"]);
    if(isset($_SESS ION['backtolist']))
    header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
    ".$_SESSION['backtolist_pag e']);
    else
    header("Locatio n: yourauctions.ph p?PAGE=
    ".$_SESSION['backtolist_pag e']);
    exit;
    }
    if($sessionVars["SELL_actio n"]=="reopen") {
    unset($_SESSION["sessionVar s"]);
    unset($_SESSION["RELISTEDAUCTIO N"]);
    header("Locatio n: yourauctions_c. php?PAGE=
    ".$_SESSION['backtolist_pag e']);
    exit;
    }
    }
    } elseif($SETTING S["feetype"] == "prepay") {
    if(!$sessionVar s["SELL_actio n"]) {
    //include "header.php ";
    }
    include "lib/auctionsetup_pa yment.php";
    } else {
    if($sessionVars["SELL_actio n"]) {
    include "header.php ";
    include phpa_include("t emplate_menu_ph p.html");
    }
    ?>

    thanks,
  • sheldonlg

    #2
    Re: nested if's

    JRough wrote:
    I got lost on formatting the nested if/else's on the bottom of the
    file right up the last else/if there seems to be a stray bracket. I'm
    trying to line up the brackets so I can read it. Is it okay to split
    a long line setting a variable on two lines at the equals sign? That
    is so you can read it in google groups.
    >
    <?
    //Send payement advices
    $TPL_auction_id = $auction_id;
    $user_id=$userr ec["id"];
    if(!$sessionVar s["SELL_actio n"]) {
    include "header.php ";
    }
    if($FEE>0) {
    if($SETTINGS["invoicing"] == 'y') {
    if(!$sessionVar s["SELL_actio n"]=="edit") {
    include phpa_include("t emplate_menu_ph p.html");
    include phpa_include("t emplate_sell_re sult_php.html") ;
    } else {
    $auction_url =
    $SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;
    if($sessionVars["SELL_actio n"]=="edit") {
    unset($_SESSION["sessionVar s"]);
    unset($_SESSION["RELISTEDAUCTIO N"]);
    if(isset($_SESS ION['backtolist']))
    header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
    ".$_SESSION['backtolist_pag e']);
    else
    header("Locatio n: yourauctions.ph p?PAGE=
    ".$_SESSION['backtolist_pag e']);
    exit;
    }
    if($sessionVars["SELL_actio n"]=="reopen") {
    unset($_SESSION["sessionVar s"]);
    unset($_SESSION["RELISTEDAUCTIO N"]);
    header("Locatio n: yourauctions_c. php?PAGE=
    ".$_SESSION['backtolist_pag e']);
    exit;
    }
    }
    } elseif($SETTING S["feetype"] == "prepay") {
    if(!$sessionVar s["SELL_actio n"]) {
    //include "header.php ";
    }
    include "lib/auctionsetup_pa yment.php";
    } else {
    if($sessionVars["SELL_actio n"]) {
    include "header.php ";
    include phpa_include("t emplate_menu_ph p.html");
    }
    ?>
    >
    thanks,
    php is a not a card-image language like Forran. It is a free-form,
    sentence language where each sentence ends in a semicolon. Thus, you
    can have a sentence over more than one line.

    Comment

    • Barry

      #3
      Re: nested if's


      <sheldonlgwro te in message
      news:FK6dncMtVL 8RcLTVnZ2dnUVZ_ vSdnZ2d@giganew s.com...
      JRough wrote:
      >I got lost on formatting the nested if/else's on the bottom of the
      >file right up the last else/if there seems to be a stray bracket. I'm
      >trying to line up the brackets so I can read it. Is it okay to split
      >a long line setting a variable on two lines at the equals sign? That
      >is so you can read it in google groups.
      >>
      ><?
      >//Send payement advices
      >$TPL_auction_i d = $auction_id;
      >$user_id=$user rec["id"];
      >if(!$sessionVa rs["SELL_actio n"]) {
      >include "header.php ";
      >}
      >if($FEE>0) {
      >if($SETTINGS["invoicing"] == 'y') {
      >if(!$sessionVa rs["SELL_actio n"]=="edit") {
      >include phpa_include("t emplate_menu_ph p.html");
      >include phpa_include("t emplate_sell_re sult_php.html") ;
      >} else {
      >$auction_url =
      >$SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;
      >if($sessionVar s["SELL_actio n"]=="edit") {
      >unset($_SESSIO N["sessionVar s"]);
      >unset($_SESSIO N["RELISTEDAUCTIO N"]);
      >if(isset($_SES SION['backtolist']))
      >header("Locati on: ".$_SESSION['backtolist']."?PAGE=
      >".$_SESSION['backtolist_pag e']);
      >else
      >header("Locati on: yourauctions.ph p?PAGE=
      >".$_SESSION['backtolist_pag e']);
      >exit;
      >}
      >if($sessionVar s["SELL_actio n"]=="reopen") {
      >unset($_SESSIO N["sessionVar s"]);
      >unset($_SESSIO N["RELISTEDAUCTIO N"]);
      >header("Locati on: yourauctions_c. php?PAGE=
      >".$_SESSION['backtolist_pag e']);
      >exit;
      >}
      >}
      >} elseif($SETTING S["feetype"] == "prepay") {
      >if(!$sessionVa rs["SELL_actio n"]) {
      >//include "header.php ";
      >}
      >include "lib/auctionsetup_pa yment.php";
      >} else {
      >if($sessionVar s["SELL_actio n"]) {
      >include "header.php ";
      >include phpa_include("t emplate_menu_ph p.html");
      >}
      >?>
      >>
      >thanks,
      >
      php is a not a card-image language like Forran. It is a free-form,
      sentence language where each sentence ends in a semicolon. Thus, you can
      have a sentence over more than one line.
      hey shelly...ur back!

      just to add, always opt for a single IF. look at your else/if...very nasty
      to read and maintain. just do an IF by itself (and FIRST) if the inner body
      has an 'exit'. then see what the others have in common. isolate the
      repetative calls with variables and 'actions'...whi ch are what is in common.
      once you've done that, actually take the action outside of ANY if...b/c this
      code is ALWAYS going to do something...you 're just using IF's to nest it.

      again, not clean or manageable.


      Comment

      • cwdjrxyz

        #4
        Re: nested if's

        On May 13, 2:24 pm, JRough <jlro...@yahoo. comwrote:
        I got lost on formatting the nested if/else's on the bottom of the
        file right up the last else/if there seems to be a stray bracket. I'm
        trying to line up the brackets so I can read it. Is it okay to split
        a long line setting a variable on two lines at the equals sign? That
        is so you can read it in google groups.
        >
        <?
        //Send payement advices
        $TPL_auction_id = $auction_id;
        $user_id=$userr ec["id"];
        if(!$sessionVar s["SELL_actio n"]) {
        include "header.php ";}
        >
        if($FEE>0) {
        if($SETTINGS["invoicing"] == 'y') {
        if(!$sessionVar s["SELL_actio n"]=="edit") {
        include phpa_include("t emplate_menu_ph p.html");
        include phpa_include("t emplate_sell_re sult_php.html") ;
        } else {
        $auction_url =
        $SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;
        if($sessionVars["SELL_actio n"]=="edit") {
        unset($_SESSION["sessionVar s"]);
        unset($_SESSION["RELISTEDAUCTIO N"]);
        if(isset($_SESS ION['backtolist']))
        header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
        ".$_SESSION['backtolist_pag e']);
        else
        header("Locatio n: yourauctions.ph p?PAGE=
        ".$_SESSION['backtolist_pag e']);
        exit;
        }
        if($sessionVars["SELL_actio n"]=="reopen") {
        unset($_SESSION["sessionVar s"]);
        unset($_SESSION["RELISTEDAUCTIO N"]);
        header("Locatio n: yourauctions_c. php?PAGE=
        ".$_SESSION['backtolist_pag e']);
        exit;
        }}
        } elseif($SETTING S["feetype"] == "prepay") {
        >
        if(!$sessionVar s["SELL_actio n"]) {
        //include "header.php ";}
        >
        include "lib/auctionsetup_pa yment.php";} else {
        >
        if($sessionVars["SELL_actio n"]) {
        include "header.php ";
        include phpa_include("t emplate_menu_ph p.html");}
        >
        ?>
        The first thing I think of when something with this much logic comes
        up is a switch statement. Of course sometimes it is not suited at all
        or only for some of the logic. However, when you can use switch, the
        code is much more orderly and easy to modify. You may have already
        considered switch and found problems in using it, so excuse me for
        bringing up the subject if that is the case. I do not have time just
        now to consider the details of your code and test them. The php switch
        is nearly the same as a Javascript switch in the formal code structure.

        Comment

        • sheldonlg

          #5
          Re: nested if's

          Barry wrote:
          <sheldonlgwro te in message
          news:FK6dncMtVL 8RcLTVnZ2dnUVZ_ vSdnZ2d@giganew s.com...
          >JRough wrote:
          >>I got lost on formatting the nested if/else's on the bottom of the
          >>file right up the last else/if there seems to be a stray bracket. I'm
          >>trying to line up the brackets so I can read it. Is it okay to split
          >>a long line setting a variable on two lines at the equals sign? That
          >>is so you can read it in google groups.
          >>>
          >><?
          >>//Send payement advices
          >>$TPL_auction_ id = $auction_id;
          >>$user_id=$use rrec["id"];
          >>if(!$sessionV ars["SELL_actio n"]) {
          >>include "header.php ";
          >>}
          >>if($FEE>0) {
          >>if($SETTING S["invoicing"] == 'y') {
          >>if(!$sessionV ars["SELL_actio n"]=="edit") {
          >>include phpa_include("t emplate_menu_ph p.html");
          >>include phpa_include("t emplate_sell_re sult_php.html") ;
          >>} else {
          >>$auction_ur l =
          >>$SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;
          >>if($sessionVa rs["SELL_actio n"]=="edit") {
          >>unset($_SESSI ON["sessionVar s"]);
          >>unset($_SESSI ON["RELISTEDAUCTIO N"]);
          >>if(isset($_SE SSION['backtolist']))
          >>header("Locat ion: ".$_SESSION['backtolist']."?PAGE=
          >>".$_SESSION['backtolist_pag e']);
          >>else
          >>header("Locat ion: yourauctions.ph p?PAGE=
          >>".$_SESSION['backtolist_pag e']);
          >>exit;
          >>}
          >>if($sessionVa rs["SELL_actio n"]=="reopen") {
          >>unset($_SESSI ON["sessionVar s"]);
          >>unset($_SESSI ON["RELISTEDAUCTIO N"]);
          >>header("Locat ion: yourauctions_c. php?PAGE=
          >>".$_SESSION['backtolist_pag e']);
          >>exit;
          >>}
          >>}
          >>} elseif($SETTING S["feetype"] == "prepay") {
          >>if(!$sessionV ars["SELL_actio n"]) {
          >>//include "header.php ";
          >>}
          >>include "lib/auctionsetup_pa yment.php";
          >>} else {
          >>if($sessionVa rs["SELL_actio n"]) {
          >>include "header.php ";
          >>include phpa_include("t emplate_menu_ph p.html");
          >>}
          >>?>
          >>>
          >>thanks,
          >php is a not a card-image language like Forran. It is a free-form,
          >sentence language where each sentence ends in a semicolon. Thus, you can
          >have a sentence over more than one line.
          >
          hey shelly...ur back!
          I was never really away. I just (a) was **extremely** busy and (2) had
          some unexpected medical issues (I'm alright). I looked in fairly
          regularly, but generally when I saw one to comment on, it had already
          been answered quite well.
          >
          just to add, always opt for a single IF. look at your else/if...very nasty
          to read and maintain. just do an IF by itself (and FIRST) if the inner body
          has an 'exit'. then see what the others have in common. isolate the
          repetative calls with variables and 'actions'...whi ch are what is in common.
          once you've done that, actually take the action outside of ANY if...b/c this
          code is ALWAYS going to do something...you 're just using IF's to nest it.
          >
          again, not clean or manageable.
          Switches are fine if you have multiple branching on a single test. He
          does have some of that with his 'if($sessionVar s["SELL_actio n"]'. In
          any event, he should go to strict two character tabs so that he doesn't
          get lost at the end of the line and have line wrap problems.

          Comment

          • Joe Butler

            #6
            Re: nested if's

            some vertical whitespace and braces around all if's and else's
            not sure yet how posting will mangle it.

            <?

            //Send payement advices
            $TPL_auction_id = $auction_id;
            $user_id= $userrec["id"];

            if(!$sessionVar s["SELL_actio n"]) {
            include "header.php ";
            }

            if($FEE 0) {
            if($SETTINGS["invoicing"] == 'y') {
            if(!$sessionVar s["SELL_actio n"] == "edit") {
            include phpa_include("t emplate_menu_ph p.html");
            include phpa_include("t emplate_sell_re sult_php.html") ;
            } else {
            $auction_url=
            $SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;

            if($sessionVars["SELL_actio n"] == "edit") {
            unset($_SESSION["sessionVar s"]);
            unset($_SESSION["RELISTEDAUCTIO N"]);

            if(isset($_SESS ION['backtolist'])){
            header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
            ".$_SESSION['backtolist_pag e']);
            }
            else{
            header("Locatio n: yourauctions.ph p?PAGE=
            ".$_SESSION['backtolist_pag e']);
            }
            exit;
            }

            if($sessionVars["SELL_actio n"]=="reopen") {
            unset($_SESSION["sessionVar s"]);
            unset($_SESSION["RELISTEDAUCTIO N"]);
            header("Locatio n: yourauctions_c. php?PAGE=
            ".$_SESSION['backtolist_pag e']);
            exit;
            }
            }
            } elseif($SETTING S["feetype"] == "prepay") {
            if(!$sessionVar s["SELL_actio n"]) {
            //include "header.php ";
            }
            include "lib/auctionsetup_pa yment.php";
            } else {

            if($sessionVars["SELL_actio n"]) {
            include "header.php ";
            include phpa_include("t emplate_menu_ph p.html");
            }

            // } missing close else brace
            ?>


            "JRough" <jlrough@yahoo. comwrote in message
            news:447949f1-85eb-4353-a708-06c59f4bf21a@u1 2g2000prd.googl egroups.com...
            >I got lost on formatting the nested if/else's on the bottom of the
            file right up the last else/if there seems to be a stray bracket. I'm
            trying to line up the brackets so I can read it. Is it okay to split
            a long line setting a variable on two lines at the equals sign? That
            is so you can read it in google groups.
            >
            <?
            //Send payement advices
            $TPL_auction_id = $auction_id;
            $user_id=$userr ec["id"];
            if(!$sessionVar s["SELL_actio n"]) {
            include "header.php ";
            }
            if($FEE>0) {
            if($SETTINGS["invoicing"] == 'y') {
            if(!$sessionVar s["SELL_actio n"]=="edit") {
            include phpa_include("t emplate_menu_ph p.html");
            include phpa_include("t emplate_sell_re sult_php.html") ;
            } else {
            $auction_url =
            $SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;
            if($sessionVars["SELL_actio n"]=="edit") {
            unset($_SESSION["sessionVar s"]);
            unset($_SESSION["RELISTEDAUCTIO N"]);
            if(isset($_SESS ION['backtolist']))
            header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
            ".$_SESSION['backtolist_pag e']);
            else
            header("Locatio n: yourauctions.ph p?PAGE=
            ".$_SESSION['backtolist_pag e']);
            exit;
            }
            if($sessionVars["SELL_actio n"]=="reopen") {
            unset($_SESSION["sessionVar s"]);
            unset($_SESSION["RELISTEDAUCTIO N"]);
            header("Locatio n: yourauctions_c. php?PAGE=
            ".$_SESSION['backtolist_pag e']);
            exit;
            }
            }
            } elseif($SETTING S["feetype"] == "prepay") {
            if(!$sessionVar s["SELL_actio n"]) {
            //include "header.php ";
            }
            include "lib/auctionsetup_pa yment.php";
            } else {
            if($sessionVars["SELL_actio n"]) {
            include "header.php ";
            include phpa_include("t emplate_menu_ph p.html");
            }
            ?>
            >
            thanks,

            Comment

            • Jerry Stuckle

              #7
              Re: nested if's

              JRough wrote:
              I got lost on formatting the nested if/else's on the bottom of the
              file right up the last else/if there seems to be a stray bracket. I'm
              trying to line up the brackets so I can read it. Is it okay to split
              a long line setting a variable on two lines at the equals sign? That
              is so you can read it in google groups.
              >
              <snip code>
              >
              thanks,
              >
              Joe beat me to it :-)

              In addition, get yourself an editor with syntax highlighting. The main
              one I use is Crimson Editor (http://www.crimsoneditor.com/) - free, fast
              and good.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Barry

                #8
                Re: nested if's


                <sheldonlgwro te in message
                news:ssydnT8Pib rE3LfVnZ2dnUVZ_ uCdnZ2d@giganew s.com...
                Barry wrote:
                ><sheldonlgwrot e in message
                >news:FK6dncMtV L8RcLTVnZ2dnUVZ _vSdnZ2d@gigane ws.com...
                >>JRough wrote:
                >>>I got lost on formatting the nested if/else's on the bottom of the
                >>>file right up the last else/if there seems to be a stray bracket. I'm
                >>>trying to line up the brackets so I can read it. Is it okay to split
                >>>a long line setting a variable on two lines at the equals sign? That
                >>>is so you can read it in google groups.
                >>>>
                >>><?
                >>>//Send payement advices
                >>>$TPL_auction _id = $auction_id;
                >>>$user_id=$us errec["id"];
                >>>if(!$session Vars["SELL_actio n"]) {
                >>>include "header.php ";
                >>>}
                >>>if($FEE>0) {
                >>>if($SETTIN GS["invoicing"] == 'y') {
                >>>if(!$session Vars["SELL_actio n"]=="edit") {
                >>>include phpa_include("t emplate_menu_ph p.html");
                >>>include phpa_include("t emplate_sell_re sult_php.html") ;
                >>>} else {
                >>>$auction_u rl =
                >>>$SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;
                >>>if($sessionV ars["SELL_actio n"]=="edit") {
                >>>unset($_SESS ION["sessionVar s"]);
                >>>unset($_SESS ION["RELISTEDAUCTIO N"]);
                >>>if(isset($_S ESSION['backtolist']))
                >>>header("Loca tion: ".$_SESSION['backtolist']."?PAGE=
                >>>".$_SESSIO N['backtolist_pag e']);
                >>>else
                >>>header("Loca tion: yourauctions.ph p?PAGE=
                >>>".$_SESSIO N['backtolist_pag e']);
                >>>exit;
                >>>}
                >>>if($sessionV ars["SELL_actio n"]=="reopen") {
                >>>unset($_SESS ION["sessionVar s"]);
                >>>unset($_SESS ION["RELISTEDAUCTIO N"]);
                >>>header("Loca tion: yourauctions_c. php?PAGE=
                >>>".$_SESSIO N['backtolist_pag e']);
                >>>exit;
                >>>}
                >>>}
                >>>} elseif($SETTING S["feetype"] == "prepay") {
                >>>if(!$session Vars["SELL_actio n"]) {
                >>>//include "header.php ";
                >>>}
                >>>include "lib/auctionsetup_pa yment.php";
                >>>} else {
                >>>if($sessionV ars["SELL_actio n"]) {
                >>>include "header.php ";
                >>>include phpa_include("t emplate_menu_ph p.html");
                >>>}
                >>>?>
                >>>>
                >>>thanks,
                >>php is a not a card-image language like Forran. It is a free-form,
                >>sentence language where each sentence ends in a semicolon. Thus, you
                >>can have a sentence over more than one line.
                >>
                >hey shelly...ur back!
                >
                I was never really away. I just (a) was **extremely** busy and (2) had
                some unexpected medical issues (I'm alright). I looked in fairly
                regularly, but generally when I saw one to comment on, it had already been
                answered quite well.
                >
                >>
                >just to add, always opt for a single IF. look at your else/if...very
                >nasty to read and maintain. just do an IF by itself (and FIRST) if the
                >inner body has an 'exit'. then see what the others have in common.
                >isolate the repetative calls with variables and 'actions'...whi ch are
                >what is in common. once you've done that, actually take the action
                >outside of ANY if...b/c this code is ALWAYS going to do
                >something...yo u're just using IF's to nest it.
                >>
                >again, not clean or manageable.
                >
                Switches are fine if you have multiple branching on a single test. He
                does have some of that with his 'if($sessionVar s["SELL_actio n"]'. In any
                event, he should go to strict two character tabs so that he doesn't get
                lost at the end of the line and have line wrap problems.
                right...i meant reducing the if/else's themselves...li ke:

                if ($someVar)
                {
                // some action
                exit;
                }
                // no 'else' nesting required because logically it is not needed.

                just a nuance though. but yes, sell_action is redundantly analyzed and done
                so, far apart in the nesting which could get confusing. a little more than
                6, 1, 0.5, the other...but not much more based on the snippet. i agree with
                you that the first, best thing to do is simply provide better formatting.

                glad you're alright! i'll email you later...it's been a while.


                Comment

                • C. (http://symcbean.blogspot.com/)

                  #9
                  Re: nested if's

                  On 13 May, 23:43, cwdjrxyz <spamtr...@cwdj r.infowrote:
                  On May 13, 2:24 pm, JRough <jlro...@yahoo. comwrote:
                  >
                  >
                  >
                  I got lost on formatting the nested if/else's on the bottom of the
                  file right up the last else/if there seems to be a stray bracket. I'm
                  trying to line up the brackets so I can read it. Is it okay to split
                  a long line setting a variable on two lines at the equals sign? That
                  is so you can read it in google groups.
                  >
                  <?
                  //Send payement advices
                  $TPL_auction_id = $auction_id;
                  $user_id=$userr ec["id"];
                  if(!$sessionVar s["SELL_actio n"]) {
                  include "header.php ";}
                  >
                  if($FEE>0) {
                  if($SETTINGS["invoicing"] == 'y') {
                  if(!$sessionVar s["SELL_actio n"]=="edit") {
                  include phpa_include("t emplate_menu_ph p.html");
                  include phpa_include("t emplate_sell_re sult_php.html") ;
                  } else {
                  $auction_url =
                  $SETTINGS["siteurl"] . "item.php?mode= 1&id=".$auction _id;
                  if($sessionVars["SELL_actio n"]=="edit") {
                  unset($_SESSION["sessionVar s"]);
                  unset($_SESSION["RELISTEDAUCTIO N"]);
                  if(isset($_SESS ION['backtolist']))
                  header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
                  ".$_SESSION['backtolist_pag e']);
                  else
                  header("Locatio n: yourauctions.ph p?PAGE=
                  ".$_SESSION['backtolist_pag e']);
                  exit;
                  }
                  if($sessionVars["SELL_actio n"]=="reopen") {
                  unset($_SESSION["sessionVar s"]);
                  unset($_SESSION["RELISTEDAUCTIO N"]);
                  header("Locatio n: yourauctions_c. php?PAGE=
                  ".$_SESSION['backtolist_pag e']);
                  exit;
                  }}
                  } elseif($SETTING S["feetype"] == "prepay") {
                  >
                  if(!$sessionVar s["SELL_actio n"]) {
                  //include "header.php ";}
                  >
                  include "lib/auctionsetup_pa yment.php";} else {
                  >
                  if($sessionVars["SELL_actio n"]) {
                  include "header.php ";
                  include phpa_include("t emplate_menu_ph p.html");}
                  >
                  ?>
                  >
                  The first thing I think of when something with this much logic comes
                  up is a switch statement. Of course sometimes it is not suited at all
                  or only for some of the logic. However, when you can use switch, the
                  code is much more orderly and easy to modify. You may have already
                  considered switch and found problems in using it, so excuse me for
                  bringing up the subject if that is the case. I do not have time just
                  now to consider the details of your code and test them. The php switch
                  is nearly the same as a Javascript switch in the formal code structure.
                  A PHP switch statement only really works on the value(s) of a single
                  expression - the code above relies on multiple experssions. I'd agree
                  that the code above is rather messy and difficult to maintain.
                  Certainly end brackets of nested blocks should be commented to
                  reference the start point. It already looks as if it needs fixed:

                  if(!$sessionVar s["SELL_actio n"]=="edit") {
                  ....
                  } else {
                  ...
                  if($sessionVars["SELL_actio n"]=="edit") {


                  There's other ways to make the code clearer though:
                  You could break it down into seperate functions.
                  The indentiy of include files is alerady encapsulated in a function
                  (presumably for path rewriting) you could push the logic for determing
                  which include files to use further down the call tree.
                  You could bundle the different scenarios under single level if ...
                  elseif ...else statements
                  e.g.

                  //Send payement advices
                  $TPL_auction_id = $auction_id;
                  $user_id=$userr ec["id"];

                  if ((!$sessionVars["SELL_actio n"]) || ($FEE<=0) {
                  include "header.php ";
                  }
                  if (($FEE>0) && (($SETTINGS["invoicing"] == 'y') && (!
                  $sessionVars["SELL_actio n"]=="edit")) {
                  include phpa_include("t emplate_menu_ph p.html");
                  include phpa_include("t emplate_sell_re sult_php.html") ;
                  }
                  if (($FEE>0) && (($SETTINGS["invoicing"] == 'y') && (!
                  $sessionVars["SELL_actio n"]!="edit")) {
                  $auction_url = $SETTINGS["siteurl"] . "item.php?mode= 1&id=".
                  $auction_id;
                  }
                  ....

                  Another problem with the code is that it seems to rely on inline
                  (main) code within include functions - which can introduce lots of
                  unexpected side-effects and create vulnerabilities . As a general rule
                  I don't have any inline code other than defines in include files. If
                  you use OO then you can use the autlolader to selectively load
                  libraries.

                  Another thing I note is that you use include throughout where require
                  might_once might be more appropriate.

                  Sorry OP, but the length of your lines is the least of your worries.
                  You should start by reading up on Karnaugh maps and boolean algebra.

                  C.

                  Comment

                  • Barry

                    #10
                    Re: nested if's


                    "C. (http://symcbean.blogsp ot.com/)" <colin.mckinnon @gmail.comwrote in
                    message
                    news:8622be3e-f7a6-4d07-8d12-f25f9ca71f5f@r6 6g2000hsg.googl egroups.com...
                    On 13 May, 23:43, cwdjrxyz <spamtr...@cwdj r.infowrote:
                    >On May 13, 2:24 pm, JRough <jlro...@yahoo. comwrote:
                    >>
                    >>
                    >>
                    I got lost on formatting the nested if/else's on the bottom of the
                    file right up the last else/if there seems to be a stray bracket. I'm
                    trying to line up the brackets so I can read it. Is it okay to split
                    a long line setting a variable on two lines at the equals sign? That
                    is so you can read it in google groups.
                    >>
                    <?
                    //Send payement advices
                    $TPL_auction_id = $auction_id;
                    $user_id=$userr ec["id"];
                    if(!$sessionVar s["SELL_actio n"]) {
                    include "header.php ";}
                    >>
                    if($FEE>0) {
                    if($SETTINGS["invoicing"] == 'y') {
                    if(!$sessionVar s["SELL_actio n"]=="edit") {
                    include phpa_include("t emplate_menu_ph p.html");
                    include
                    phpa_include("t emplate_sell_re sult_php.html") ;
                    } else {
                    $auction_url =
                    $SETTINGS["siteurl"] .
                    "item.php?mode= 1&id=".$auction _id;
                    if($sessionVars["SELL_actio n"]=="edit")
                    {
                    >
                    unset($_SESSION["sessionVar s"]);
                    >
                    unset($_SESSION["RELISTEDAUCTIO N"]);
                    >
                    if(isset($_SESS ION['backtolist']))
                    >
                    header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
                    >
                    ".$_SESSION['backtolist_pag e']);
                    else
                    >
                    header("Locatio n: yourauctions.ph p?PAGE=
                    >
                    ".$_SESSION['backtolist_pag e']);
                    exit;
                    }
                    if($sessionVars["SELL_actio n"]=="reopen") {
                    unset($_SESSION["sessionVar s"]);
                    unset($_SESSION["RELISTEDAUCTIO N"]);
                    header("Locatio n: yourauctions_c. php?PAGE=
                    ".$_SESSION['backtolist_pag e']);
                    exit;
                    }}
                    } elseif($SETTING S["feetype"] == "prepay") {
                    >>
                    if(!$sessionVar s["SELL_actio n"]) {
                    //include "header.php ";}
                    >>
                    include "lib/auctionsetup_pa yment.php";} else {
                    >>
                    if($sessionVars["SELL_actio n"]) {
                    include "header.php ";
                    include phpa_include("t emplate_menu_ph p.html");}
                    >>
                    ?>
                    >>
                    >The first thing I think of when something with this much logic comes
                    >up is a switch statement. Of course sometimes it is not suited at all
                    >or only for some of the logic. However, when you can use switch, the
                    >code is much more orderly and easy to modify. You may have already
                    >considered switch and found problems in using it, so excuse me for
                    >bringing up the subject if that is the case. I do not have time just
                    >now to consider the details of your code and test them. The php switch
                    >is nearly the same as a Javascript switch in the formal code structure.
                    >
                    A PHP switch statement only really works on the value(s) of a single
                    expression - the code above relies on multiple experssions.
                    switch (true)
                    {
                    case $sessionVars['SELL_action'] == 'edit' :
                    }

                    that's a single expression value...you can have as little or as few
                    expressions in 'case'. php would be looking for 'true'.
                    I'd agree
                    that the code above is rather messy and difficult to maintain.
                    Certainly end brackets of nested blocks should be commented to
                    reference the start point. It already looks as if it needs fixed:
                    >
                    if(!$sessionVar s["SELL_actio n"]=="edit") {
                    ....
                    } else {
                    ...
                    if($sessionVars["SELL_actio n"]=="edit") {
                    >
                    >
                    There's other ways to make the code clearer though:
                    You could break it down into seperate functions.
                    The indentiy of include files is alerady encapsulated in a function
                    (presumably for path rewriting) you could push the logic for determing
                    which include files to use further down the call tree.
                    You could bundle the different scenarios under single level if ...
                    elseif ...else statements
                    e.g.
                    >
                    //Send payement advices
                    $TPL_auction_id = $auction_id;
                    $user_id=$userr ec["id"];
                    >
                    if ((!$sessionVars["SELL_actio n"]) || ($FEE<=0) {
                    include "header.php ";
                    }
                    if (($FEE>0) && (($SETTINGS["invoicing"] == 'y') && (!
                    $sessionVars["SELL_actio n"]=="edit")) {
                    include phpa_include("t emplate_menu_ph p.html");
                    include phpa_include("t emplate_sell_re sult_php.html") ;
                    }
                    if (($FEE>0) && (($SETTINGS["invoicing"] == 'y') && (!
                    $sessionVars["SELL_actio n"]!="edit")) {
                    $auction_url = $SETTINGS["siteurl"] . "item.php?mode= 1&id=".
                    $auction_id;
                    }
                    ...
                    you have to be careful though, since if/elseif/else constructs are
                    exclusionary. not nesting the if's when needed will have less than
                    beneficial results.
                    Another problem with the code is that it seems to rely on inline
                    (main) code within include functions - which can introduce lots of
                    unexpected side-effects and create vulnerabilities . As a general rule
                    I don't have any inline code other than defines in include files. If
                    you use OO then you can use the autlolader to selectively load
                    libraries.
                    >
                    Another thing I note is that you use include throughout where require
                    might_once might be more appropriate.
                    >
                    Sorry OP, but the length of your lines is the least of your worries.
                    You should start by reading up on Karnaugh maps and boolean algebra.
                    lol. that's a thought.


                    Comment

                    • JRough

                      #11
                      Re: nested if's

                      On May 13, 6:53 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                      JRough wrote:
                      I got lost on formatting the nested if/else's on the bottom of the
                      file right up the last else/if there seems to be a stray bracket. I'm
                      trying to line up the brackets so I can read it. Is it okay to split
                      a long line setting a variable on two lines at the equals sign? That
                      is so you can read it in google groups.
                      >
                      <snip code>
                      >
                      thanks,
                      >
                      Joe beat me to it :-)
                      >
                      In addition, get yourself an editor with syntax highlighting. The main
                      one I use is Crimson Editor (http://www.crimsoneditor.com/) - free, fast
                      and good.
                      >
                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstuck...@attgl obal.net
                      =============== ===
                      tnx, I was wondering if there was a case statement, I will look for
                      the switch instead, I'm coming from programming in VBA.

                      Comment

                      • JRough

                        #12
                        Re: nested if's

                        On May 14, 9:03 am, "Barry" <no....@example .comwrote:
                        "C. (http://symcbean.blogsp ot.com/)" <colin.mckin... @gmail.comwrote in
                        messagenews:862 2be3e-f7a6-4d07-8d12-f25f9ca71f5f@r6 6g2000hsg.googl egroups.com...
                        >
                        >
                        >
                        On 13 May, 23:43, cwdjrxyz <spamtr...@cwdj r.infowrote:
                        On May 13, 2:24 pm, JRough <jlro...@yahoo. comwrote:
                        >
                        I got lost on formatting the nested if/else's on the bottom of the
                        file right up the last else/if there seems to be a stray bracket. I'm
                        trying to line up the brackets so I can read it. Is it okay to split
                        a long line setting a variable on two lines at the equals sign? That
                        is so you can read it in google groups.
                        >
                        <?
                        //Send payement advices
                        $TPL_auction_id = $auction_id;
                        $user_id=$userr ec["id"];
                        if(!$sessionVar s["SELL_actio n"]) {
                        include "header.php ";}
                        >
                        if($FEE>0) {
                        if($SETTINGS["invoicing"] == 'y') {
                        if(!$sessionVar s["SELL_actio n"]=="edit") {
                        include phpa_include("t emplate_menu_ph p.html");
                        include
                        phpa_include("t emplate_sell_re sult_php.html") ;
                        } else {
                        $auction_url =
                        $SETTINGS["siteurl"] .
                        "item.php?mode= 1&id=".$auction _id;
                        if($sessionVars["SELL_actio n"]=="edit")
                        {
                        >
                        unset($_SESSION["sessionVar s"]);
                        >
                        unset($_SESSION["RELISTEDAUCTIO N"]);
                        >
                        if(isset($_SESS ION['backtolist']))
                        >
                        header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
                        >
                        ".$_SESSION['backtolist_pag e']);
                        else
                        >
                        header("Locatio n: yourauctions.ph p?PAGE=
                        >
                        ".$_SESSION['backtolist_pag e']);
                        exit;
                        }
                        if($sessionVars["SELL_actio n"]=="reopen") {
                        unset($_SESSION["sessionVar s"]);
                        unset($_SESSION["RELISTEDAUCTIO N"]);
                        header("Locatio n: yourauctions_c. php?PAGE=
                        ".$_SESSION['backtolist_pag e']);
                        exit;
                        }}
                        } elseif($SETTING S["feetype"] == "prepay") {
                        >
                        if(!$sessionVar s["SELL_actio n"]) {
                        //include "header.php ";}
                        >
                        include "lib/auctionsetup_pa yment.php";} else {
                        >
                        if($sessionVars["SELL_actio n"]) {
                        include "header.php ";
                        include phpa_include("t emplate_menu_ph p.html");}
                        >
                        ?>
                        >
                        The first thing I think of when something with this much logic comes
                        up is a switch statement. Of course sometimes it is not suited at all
                        or only for some of the logic. However, when you can use switch, the
                        code is much more orderly and easy to modify. You may have already
                        considered switch and found problems in using it, so excuse me for
                        bringing up the subject if that is the case. I do not have time just
                        now to consider the details of your code and test them. The php switch
                        is nearly the same as a Javascript switch in the formal code structure.
                        >
                        A PHP switch statement only really works on the value(s) of a single
                        expression - the code above relies on multiple experssions.
                        >
                        switch (true)
                        {
                        case $sessionVars['SELL_action'] == 'edit' :
                        >
                        }
                        >
                        that's a single expression value...you can have as little or as few
                        expressions in 'case'. php would be looking for 'true'.
                        >
                        >
                        >
                        I'd agree
                        that the code above is rather messy and difficult to maintain.
                        Certainly end brackets of nested blocks should be commented to
                        reference the start point. It already looks as if it needs fixed:
                        >
                        if(!$sessionVar s["SELL_actio n"]=="edit") {
                        ....
                        } else {
                        ...
                        if($sessionVars["SELL_actio n"]=="edit") {
                        >
                        There's other ways to make the code clearer though:
                        You could break it down into seperate functions.
                        The indentiy of include files is alerady encapsulated in a function
                        (presumably for path rewriting) you could push the logic for determing
                        which include files to use further down the call tree.
                        You could bundle the different scenarios under single level if ...
                        elseif ...else statements
                        e.g.
                        >
                        //Send payement advices
                        $TPL_auction_id = $auction_id;
                        $user_id=$userr ec["id"];
                        >
                        if ((!$sessionVars["SELL_actio n"]) || ($FEE<=0) {
                        include "header.php ";
                        }
                        if (($FEE>0) && (($SETTINGS["invoicing"] == 'y') && (!
                        $sessionVars["SELL_actio n"]=="edit")) {
                        include phpa_include("t emplate_menu_ph p.html");
                        include phpa_include("t emplate_sell_re sult_php.html") ;
                        }
                        if (($FEE>0) && (($SETTINGS["invoicing"] == 'y') && (!
                        $sessionVars["SELL_actio n"]!="edit")) {
                        $auction_url = $SETTINGS["siteurl"] . "item.php?mode= 1&id=".
                        $auction_id;
                        }
                        ...
                        >
                        you have to be careful though, since if/elseif/else constructs are
                        exclusionary. not nesting the if's when needed will have less than
                        beneficial results.
                        >
                        Another problem with the code is that it seems to rely on inline
                        (main) code within include functions - which can introduce lots of
                        unexpected side-effects and create vulnerabilities . As a general rule
                        I don't have any inline code other than defines in include files. If
                        you use OO then you can use the autlolader to selectively load
                        libraries.
                        >
                        Another thing I note is that you use include throughout where require
                        might_once might be more appropriate.
                        >
                        Sorry OP, but the length of your lines is the least of your worries.
                        You should start by reading up on Karnaugh maps and boolean algebra.
                        >
                        lol. that's a thought.
                        thanks,

                        Comment

                        • C. (http://symcbean.blogspot.com/)

                          #13
                          Re: nested if's

                          On 14 May, 17:03, "Barry" <no....@example .comwrote:
                          "C. (http://symcbean.blogsp ot.com/)" <colin.mckin... @gmail.comwrote in
                          messagenews:862 2be3e-f7a6-4d07-8d12-f25f9ca71f5f@r6 6g2000hsg.googl egroups.com...
                          >
                          A PHP switch statement only really works on the value(s) of a single
                          expression - the code above relies on multiple experssions.
                          >
                          switch (true)
                          {
                          case $sessionVars['SELL_action'] == 'edit' :
                          >
                          }
                          >
                          that's a single expression value...you can have as little or as few
                          expressions in 'case'. php would be looking for 'true'.
                          Cool. I should have thought of that.

                          Ta

                          C.

                          Comment

                          • Alexey Kulentsov

                            #14
                            Re: nested if's

                            JRough wrote:
                            trying to line up the brackets so I can read it. Is it okay to split
                            a long line setting a variable on two lines at the equals sign? That
                            ....
                            header("Locatio n: ".$_SESSION['backtolist']."?PAGE=
                            ".$_SESSION['backtolist_pag e']);
                            No. End of line and all these spaces now are parts of text constant
                            and will go direct to string. It's bad. Do break on point operator:

                            header("Locatio n: ".$_SESSION['backtolist']."?PAGE="
                            .$_SESSION['backtolist_pag e']);

                            And use functions to reduce nesting level.

                            Comment

                            Working...