If statement within an if statement

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

    If statement within an if statement

    I am a complete novice with php scrip but I am wiling to learn.
    I am in need of some help, please.

    Can anyone sort this code out for me so that it works correctly and
    adjusts the price for the quantity selected on the front end.
    _______________ _______________ _______________ _______________ ___

    if(article_get_ field('type')== 'Croclight Candle'){
    article_set_fie ld('item_number ', 'CRC');
    article_set_fie ld('price', 6.99);
    }
    elseif(article_ get_field('type ')== 'Spray') {
    article_set_fie ld('item_number ', 'CRS');
    article_set_fie ld('size', '50ml');
    article_set_fie ld('price', 6.99);
    }
    elseif(article_ get_field('size ')== '15ml') {
    article_set_fie ld('item_number ', 'CRS');
    article_set_fie ld('type', 'Spray');
    article_set_fie ld('price', 2.99);
    }
    elseif(article_ get_field('type ')== 'Roll-on') {
    article_set_fie ld('item_number ', 'CRO');
    article_set_fie ld('size', '50ml');
    article_set_fie ld('price', 6.99);
    }
    _______________ _______________ _______________ _______________ ____

    Thanks in advance

    Mark

  • Ken Robinson

    #2
    Re: If statement within an if statement

    "Mark" <mark.whitehead @ntlworld.com> wrote in
    news:1124744790 .953402.277870@ g49g2000cwa.goo glegroups.com:
    [color=blue]
    > I am a complete novice with php scrip but I am wiling to learn.
    > I am in need of some help, please.
    >
    > Can anyone sort this code out for me so that it works correctly and
    > adjusts the price for the quantity selected on the front end.
    > _______________ _______________ _______________ _______________ ___
    >
    > if(article_get_ field('type')== 'Croclight Candle'){
    > article_set_fie ld('item_number ', 'CRC');
    > article_set_fie ld('price', 6.99);
    > }
    > elseif(article_ get_field('type ')== 'Spray') {
    > article_set_fie ld('item_number ', 'CRS');
    > article_set_fie ld('size', '50ml');
    > article_set_fie ld('price', 6.99);
    > }
    > elseif(article_ get_field('size ')== '15ml') {
    > article_set_fie ld('item_number ', 'CRS');
    > article_set_fie ld('type', 'Spray');
    > article_set_fie ld('price', 2.99);
    > }
    > elseif(article_ get_field('type ')== 'Roll-on') {
    > article_set_fie ld('item_number ', 'CRO');
    > article_set_fie ld('size', '50ml');
    > article_set_fie ld('price', 6.99);
    > }[/color]

    First suggestion: Avoid elseif's if at all possible. Use the switch()
    statement instead. <see http://www.php.net/switch>

    switch (article_get_fi eld('type')) {
    case 'Croclight Candle':
    article_set_fie ld('item_number ', 'CRC');
    article_set_fie ld('price', 6.99);
    break;
    case 'Spray':
    article_set_fie ld('item_number ', 'CRS');
    article_set_fie ld('size', '50ml');
    article_set_fie ld('price', 6.99);
    break;
    case 'Roll-on':
    article_set_fie ld('item_number ', 'CRO');
    article_set_fie ld('size', '50ml');
    article_set_fie ld('price', 6.99);
    break;
    }

    if(article_get_ field('size') == '15ml') {
    article_set_fie ld('item_number ', 'CRS');
    article_set_fie ld('type', 'Spray');
    article_set_fie ld('price', 2.99);
    }

    Also, when posting code, try to use indentation so that the different
    code blocks can be determined.

    Ken



    Comment

    • PHPGB

      #3
      Re: If statement within an if statement

      <comp.lang.ph p , Ken Robinson , sendspamhere@rb nsn.com>
      <1124745948.eba 2d174dc98eac000 e32e39523bcf98@ teranews>
      <Mon, 22 Aug 2005 21:25:48 GMT>
      [color=blue]
      > First suggestion: Avoid elseif's if at all possible. Use the switch()
      > statement instead. <see http://www.php.net/switch>
      >
      > switch (article_get_fi eld('type')) {snip code}
      >
      > Also, when posting code, try to use indentation so that the different
      > code blocks can be determined.
      >[/color]

      That looked a nice bit of code and i've been meaning to learn about
      switch() for ages , But i'm the opposite and most of the time I regard
      indents as a curse .

      if ($poo<>$poo)
      {
      php code
      }

      Each to their own .


      --

      Comment

      • Default User

        #4
        Re: If statement within an if statement

        PHPGB wrote:

        [color=blue]
        > That looked a nice bit of code and i've been meaning to learn about
        > switch() for ages , But i'm the opposite and most of the time I
        > regard indents as a curse .
        >
        > if ($poo<>$poo)
        > {
        > php code
        > }
        >
        > Each to their own .[/color]


        You'll find that proper indentation is almost universal amongst
        programmers. There's a very good reason for that, having to do with
        being able to read, debug, and maintain large code sections.

        I recommend strongly that you start doing the same. Many code editors
        help you out these days through auto-indenting. Use spaces, not tabs,
        especially for posting code to usenet.




        Brian

        Comment

        • PHPGB

          #5
          Re: If statement within an if statement

          <comp.lang.ph p , Default User , defaultuserbr@y ahoo.com>
          <3n1ke8F18bn6qU 1@individual.ne t>
          <23 Aug 2005 21:57:29 GMT>
          [color=blue][color=green]
          > > if ($poo<>$poo)
          > > {
          > > php code
          > > }
          > >
          > > Each to their own .[/color]
          >
          >
          > You'll find that proper indentation is almost universal amongst
          > programmers. There's a very good reason for that, having to do with
          > being able to read, debug, and maintain large code sections.
          >[/color]

          And if all the other programmers put their hand in the fire you would
          want me to do the same would you ? :-)

          I've always been in the frame of mind its what suits the person and not
          what suits anybody else .


          --

          Comment

          • Ramon

            #6
            Re: If statement within an if statement

            Fair enouph, just dont expect assistance from the community then.

            PHPGB wrote:[color=blue]
            > <comp.lang.ph p , Default User , defaultuserbr@y ahoo.com>
            > <3n1ke8F18bn6qU 1@individual.ne t>
            > <23 Aug 2005 21:57:29 GMT>
            >[color=green][color=darkred]
            >>>if ($poo<>$poo)
            >>>{
            >>>php code
            >>>}
            >>>
            >>>Each to their own .[/color]
            >>
            >>
            >>You'll find that proper indentation is almost universal amongst
            >>programmers . There's a very good reason for that, having to do with
            >>being able to read, debug, and maintain large code sections.
            >>[/color]
            >
            >
            > And if all the other programmers put their hand in the fire you would
            > want me to do the same would you ? :-)
            >
            > I've always been in the frame of mind its what suits the person and not
            > what suits anybody else .
            >
            >[/color]

            Comment

            • Jerry Stuckle

              #7
              Re: If statement within an if statement

              PHPGB wrote:[color=blue]
              > <comp.lang.ph p , Default User , defaultuserbr@y ahoo.com>
              > <3n1ke8F18bn6qU 1@individual.ne t>
              > <23 Aug 2005 21:57:29 GMT>
              >[color=green][color=darkred]
              >>>if ($poo<>$poo)
              >>>{
              >>>php code
              >>>}
              >>>
              >>>Each to their own .[/color]
              >>
              >>
              >>You'll find that proper indentation is almost universal amongst
              >>programmers . There's a very good reason for that, having to do with
              >>being able to read, debug, and maintain large code sections.
              >>[/color]
              >
              >
              > And if all the other programmers put their hand in the fire you would
              > want me to do the same would you ? :-)
              >
              > I've always been in the frame of mind its what suits the person and not
              > what suits anybody else .
              >
              >[/color]

              Gee, if all the other programmers were doing it, there must be a reason!

              After almost 40 years of programming, I've found indenting is VERY important.
              And I second Ramon's opinion - don't expect help from the group - or any other
              programmer. And don't expect to ever get a job programming.

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

              Comment

              • PHPGB

                #8
                Re: If statement within an if statement

                <comp.lang.ph p , Jerry Stuckle , jstucklex@attgl obal.net>
                <q5WdnYKGDPa-I5beRVn-oQ@comcast.com>
                <Tue, 23 Aug 2005 20:23:49 -0500>
                [color=blue][color=green]
                > > And if all the other programmers put their hand in the fire you would
                > > want me to do the same would you ? :-)
                > >
                > > I've always been in the frame of mind its what suits the person and not
                > > what suits anybody else .
                > >
                > >[/color]
                >
                > Gee, if all the other programmers were doing it, there must be a reason!
                >
                > After almost 40 years of programming, I've found indenting is VERY important.
                > And I second Ramon's opinion - don't expect help from the group - or any other
                > programmer.
                >[/color]

                Calm down lads .


                'don't expect help from the group'

                Do you realise what you have just said ? .

                Professional programmers acting like foot stomping little children who
                wont help a user because they use a different method than their own .


                --

                Comment

                • Default User

                  #9
                  Re: If statement within an if statement

                  PHPGB wrote:
                  [color=blue]
                  > <comp.lang.ph p , Default User , defaultuserbr@y ahoo.com>
                  > <3n1ke8F18bn6qU 1@individual.ne t>
                  > <23 Aug 2005 21:57:29 GMT>
                  >[color=green][color=darkred]
                  > > > if ($poo<>$poo)
                  > > > {
                  > > > php code
                  > > > }
                  > > >
                  > > > Each to their own .[/color]
                  > >
                  > >
                  > > You'll find that proper indentation is almost universal amongst
                  > > programmers. There's a very good reason for that, having to do with
                  > > being able to read, debug, and maintain large code sections.
                  > >[/color]
                  >
                  > And if all the other programmers put their hand in the fire you would
                  > want me to do the same would you ? :-)[/color]

                  Why would they? You seem to labor under the delusion that thousands of
                  professionals don't know what they are doing or would be malicious in
                  their advice. They do and they wouldn't be.
                  [color=blue]
                  > I've always been in the frame of mind its what suits the person and
                  > not what suits anybody else .[/color]

                  Why do you find it has any benefit?

                  More importantly, posting unindented code to the newsgroup will cause
                  at least some people to ignore you.



                  Brian

                  Comment

                  • Ramon

                    #10
                    Re: If statement within an if statement

                    No, this has nothing to do with adolescent tantrums. The reason for the
                    hostile behavior, is because after being involved in the industry. There
                    is nothing quite like walking into a new and *exciting* job opportunity,
                    and then finding that you are responsible for maintaining the code of a
                    12 year old who was stuck inside a 45 year old's body. Or simply said
                    was too lazy to comment and indent.

                    And it takes you 10x the time to interpret what was written as there is
                    no documentation of any kind (if you are lucky you will get some PHPdoc
                    crap which isnt of much use either. Oh wait, its even better if you are
                    a team leader and you are in charge of integration 10 large scale
                    systems, into one cohesive one. While because 5 out of the 10 systems in
                    question were written by this same 12 year old.

                    Still wondering where the hostility stems from? Or did you get the drift?


                    PHPGB wrote:[color=blue]
                    > <comp.lang.ph p , Jerry Stuckle , jstucklex@attgl obal.net>
                    > <q5WdnYKGDPa-I5beRVn-oQ@comcast.com>
                    > <Tue, 23 Aug 2005 20:23:49 -0500>
                    >[color=green][color=darkred]
                    >>>And if all the other programmers put their hand in the fire you would
                    >>>want me to do the same would you ? :-)
                    >>>
                    >>>I've always been in the frame of mind its what suits the person and not
                    >>>what suits anybody else .
                    >>>
                    >>>[/color]
                    >>
                    >>Gee, if all the other programmers were doing it, there must be a reason!
                    >>
                    >>After almost 40 years of programming, I've found indenting is VERY important.
                    >>And I second Ramon's opinion - don't expect help from the group - or any other
                    >>programmer.
                    >>[/color]
                    >
                    >
                    > Calm down lads .
                    >
                    >
                    > 'don't expect help from the group'
                    >
                    > Do you realise what you have just said ? .
                    >
                    > Professional programmers acting like foot stomping little children who
                    > wont help a user because they use a different method than their own .
                    >
                    >[/color]

                    Comment

                    • PHPGB

                      #11
                      Re: If statement within an if statement

                      <comp.lang.ph p , Default User , defaultuserbr@y ahoo.com>
                      <3n1u9qF195dj9U 1@individual.ne t>
                      <24 Aug 2005 00:45:46 GMT>
                      [color=blue]
                      > More importantly, posting unindented code to the newsgroup will cause
                      > at least some people to ignore you.
                      >[/color]

                      This is worse than the spanish inquisition :-)


                      --

                      Comment

                      • PHPGB

                        #12
                        Re: If statement within an if statement

                        <comp.lang.ph p , Ramon , drybkin@gmail.c om>
                        <deggcu$2bog$1@ bunyip2.cc.uq.e du.au>
                        <Wed, 24 Aug 2005 10:52:46 +1000>
                        [color=blue]
                        > Still wondering where the hostility stems from?
                        >[/color]

                        From people like yourself who appear unable or unwilling to accept other
                        peoples right to choose ? .

                        Is it safe to say you grant yourself these exact same rights without
                        even as much as a 2nd thought .


                        --

                        Comment

                        • Default User

                          #13
                          Re: If statement within an if statement

                          PHPGB wrote:
                          [color=blue]
                          > <comp.lang.ph p , Default User , defaultuserbr@y ahoo.com>
                          > <3n1u9qF195dj9U 1@individual.ne t>
                          > <24 Aug 2005 00:45:46 GMT>
                          >[color=green]
                          > > More importantly, posting unindented code to the newsgroup will
                          > > cause at least some people to ignore you.
                          > >[/color]
                          >
                          > This is worse than the spanish inquisition :-)[/color]

                          Look, it's up to you. Do what you want on your own, but people are
                          going to complain if you post unreadable code here and try to get help.




                          Brian

                          Comment

                          • Ramon

                            #14
                            Re: If statement within an if statement

                            PHPGB wrote:[color=blue]
                            > <comp.lang.ph p , Ramon , drybkin@gmail.c om>
                            > <deggcu$2bog$1@ bunyip2.cc.uq.e du.au>
                            > <Wed, 24 Aug 2005 10:52:46 +1000>
                            >[color=green]
                            >>Still wondering where the hostility stems from?
                            >>[/color]
                            >
                            >
                            > From people like yourself who appear unable or unwilling to accept other
                            > peoples right to choose ? .
                            >
                            > Is it safe to say you grant yourself these exact same rights without
                            > even as much as a 2nd thought .[/color]

                            Right to choose what? What kind of code they produce?!?

                            Here's an idea, develop something worth while and submit it to PEAR or
                            PECL. Without proper indentation and/or commenting, and the see how far
                            your peace of software gets.

                            Looks if you are working on a small project, and you are sole developer
                            thats fair enough, no one cares what you do in your own little cage. But
                            don't preach about choice, and how its a free country. Just because you
                            have the choice to do a bad job or a good job, does not mean that most
                            of us choose to do a bad one. In fact I'm proud of the work I do. There
                            no substitute for quality, and believe me when it comes to bargaining
                            about your paycheck, *choice* is of little matter to an employer/client,
                            while quality is everything in this business.

                            Cheers,

                            D

                            Comment

                            • Default User

                              #15
                              Re: If statement within an if statement

                              PHPGB wrote:
                              [color=blue]
                              > <comp.lang.ph p , Ramon , drybkin@gmail.c om>
                              > <deggcu$2bog$1@ bunyip2.cc.uq.e du.au>
                              > <Wed, 24 Aug 2005 10:52:46 +1000>
                              >[color=green]
                              > > Still wondering where the hostility stems from?
                              > >[/color]
                              >
                              > From people like yourself who appear unable or unwilling to accept
                              > other peoples right to choose ? .
                              >
                              > Is it safe to say you grant yourself these exact same rights without
                              > even as much as a 2nd thought .[/color]

                              Life's too short to deal with idiots. Seriously.

                              So, *plonk* and all that.




                              Brian

                              Comment

                              Working...