modifying 'for... loop ' with php to leave out one number

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

    #1

    modifying 'for... loop ' with php to leave out one number

    Hello
    Im using the following loop to populate a list box but I dont want th
    current selected value (from database) to show in the list
    The one I want to omitt is in the variable

    $row['bbannerorgfont ']

    I wish to some how include this in the below loop to the effect of

    echo from 0 to 6 except for $row['bbannerorgfont ']

    VB has select...case.. . etc. Is there something similar with PHP?

    <?
    for($i = 0; $i < 7; $i++) {
    echo "<option value='".$i+1." '>".$i+1."</option><br>";
    }
    ?>

    cheers ian


  • mootmail-googlegroups@yahoo.com

    #2
    Re: modifying 'for... loop ' with php to leave out one number

    Ian Davies wrote:
    VB has select...case.. . etc. Is there something similar with PHP?
    The PHP equivalent is the Switch statement
    See: http://us3.php.net/manual/en/control...res.switch.php

    Comment

    • Gary Hasler

      #3
      Re: modifying 'for... loop ' with php to leave out one number

      Like:
      ($i = 0; ($i < 7)&&($i!=$row['bbannerorgfont ']); $i++) {....
      ?

      Ian Davies wrote:
      Hello
      Im using the following loop to populate a list box but I dont want th
      current selected value (from database) to show in the list
      The one I want to omitt is in the variable
      >
      $row['bbannerorgfont ']
      >
      I wish to some how include this in the below loop to the effect of
      >
      echo from 0 to 6 except for $row['bbannerorgfont ']
      >
      VB has select...case.. . etc. Is there something similar with PHP?
      >
      <?
      for($i = 0; $i < 7; $i++) {
      echo "<option value='".$i+1." '>".$i+1."</option><br>";
      }
      ?>
      >
      cheers ian

      Comment

      • Gary Hasler

        #4
        Re: modifying 'for... loop ' with php to leave out one number

        Ignore me...it would end the loop!...duhhh.. .

        Gary Hasler wrote:
        Like:
        ($i = 0; ($i < 7)&&($i!=$row['bbannerorgfont ']); $i++) {....
        ?

        Comment

        • Alvaro G. Vicario

          #5
          Re: modifying 'for... loop ' with php to leave out one number

          *** Ian Davies escribió/wrote (Mon, 31 Jul 2006 20:16:50 GMT):
          Hello
          Im using the following loop to populate a list box but I dont want th
          current selected value (from database) to show in the list
          The one I want to omitt is in the variable
          >
          $row['bbannerorgfont ']
          [...]
          for($i = 0; $i < 7; $i++) {
          echo "<option value='".$i+1." '>".$i+1."</option><br>";
          }

          if($i != $row['bbannerorgfont ']){
          echo .......
          }

          --
          -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
          ++ Mi sitio sobre programación web: http://bits.demogracia.com
          +- Mi web de humor con rayos UVA: http://www.demogracia.com
          --

          Comment

          • Miguel Cruz

            #6
            Re: modifying 'for... loop ' with php to leave out one number

            "Ian Davies" <ian.dandav@vir gin.netwrote:
            Im using the following loop to populate a list box but I dont want th
            current selected value (from database) to show in the list
            The one I want to omitt is in the variable
            >
            $row['bbannerorgfont ']
            >
            I wish to some how include this in the below loop to the effect of
            >
            echo from 0 to 6 except for $row['bbannerorgfont ']
            >
            VB has select...case.. . etc. Is there something similar with PHP?
            switch($i)
            {
            case 0:
            do something;
            break;
            case 1:
            do something else;
            break;
            }
            <?
            for($i = 0; $i < 7; $i++) {
            echo "<option value='".$i+1." '>".$i+1."</option><br>";
            }
            ?>
            for ($i = 0; $i < 7; $i++)
            {
            if ($i == $row['bbannerorgfont '])
            continue;
            echo "<option value='" . $i + 1 . "'>" . $i + 1 . "</option><br>";
            }


            --
            Photos from 40 countries on 5 continents: http://travel.u.nu
            Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
            Airports of the world: http://airport.u.nu

            Comment

            • Ian Davies

              #7
              Re: modifying 'for... loop ' with php to leave out one number

              Thans all
              I think the switch would be best thanks
              Ian

              "Miguel Cruz" <spam@admin.u.n uwrote in message
              news:spam-61CD95.05034201 082006@localhos t...
              "Ian Davies" <ian.dandav@vir gin.netwrote:
              Im using the following loop to populate a list box but I dont want th
              current selected value (from database) to show in the list
              The one I want to omitt is in the variable

              $row['bbannerorgfont ']

              I wish to some how include this in the below loop to the effect of

              echo from 0 to 6 except for $row['bbannerorgfont ']

              VB has select...case.. . etc. Is there something similar with PHP?
              >
              switch($i)
              {
              case 0:
              do something;
              break;
              case 1:
              do something else;
              break;
              }
              >
              <?
              for($i = 0; $i < 7; $i++) {
              echo "<option value='".$i+1." '>".$i+1."</option><br>";
              }
              ?>
              >
              for ($i = 0; $i < 7; $i++)
              {
              if ($i == $row['bbannerorgfont '])
              continue;
              echo "<option value='" . $i + 1 . "'>" . $i + 1 . "</option><br>";
              }
              >
              >
              --
              Photos from 40 countries on 5 continents: http://travel.u.nu
              Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
              Airports of the world: http://airport.u.nu

              Comment

              • Kimmo Laine

                #8
                Re: modifying 'for... loop ' with php to leave out one number

                "Ian Davies" <ian.dandav@vir gin.netwrote in message
                news:Odwzg.1038 32$sz1.66846@ne wsfe6-gui.ntli.net...
                Thans all
                I think the switch would be best thanks
                No, it's just closest thing to what you've used in VB. A simple if
                statement, such as the one suggested by Miquel, would be the _best_ choice.

                --
                "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
                http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
                spam@outolempi. net || Gedoon-S @ IRCnet || rot13(xvzzb@bhg byrzcv.arg)


                Comment

                • Ian Davies

                  #9
                  Re: modifying 'for... loop ' with php to leave out one number

                  "Kimmo Laine" <spam@outolempi .netwrote in message
                  news:R7Dzg.141$ Y41.129@reader1 .news.jippii.ne t...
                  "Ian Davies" <ian.dandav@vir gin.netwrote in message
                  news:Odwzg.1038 32$sz1.66846@ne wsfe6-gui.ntli.net...
                  Thans all
                  I think the switch would be best thanks
                  >
                  No, it's just closest thing to what you've used in VB. A simple if
                  statement, such as the one suggested by Miquel, would be the _best_
                  choice.
                  >
                  --
                  "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
                  http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
                  spam@outolempi. net || Gedoon-S @ IRCnet || rot13(xvzzb@bhg byrzcv.arg)
                  >
                  >
                  Hello
                  I also realised this too and have decides afterall to go with the if
                  statement by Miquel (THANKS MIQUEL) as there will be less lines of code. Do
                  you know if there is a performance advantage over the switch method?

                  Ian


                  Comment

                  • Alvaro G. Vicario

                    #10
                    Re: modifying 'for... loop ' with php to leave out one number

                    *** Ian Davies escribió/wrote (Tue, 01 Aug 2006 10:53:54 GMT):
                    I also realised this too and have decides afterall to go with the if
                    statement by Miquel (THANKS MIQUEL) as there will be less lines of code. Do
                    you know if there is a performance advantage over the switch method?
                    Don't care about performance at this level. Just try to do what best suits
                    your code logic: it's far more important to understand your code several
                    months after your wrote it.

                    Typical performance issues are more like:

                    * Fetching 5000 database records to display the top 5
                    * Dynamically generating the very same thumbnail every time it's requested
                    * Loading a full 20MB text file into memory to process it line by line

                    --
                    -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
                    ++ Mi sitio sobre programación web: http://bits.demogracia.com
                    +- Mi web de humor con rayos UVA: http://www.demogracia.com
                    --

                    Comment

                    • Miguel Cruz

                      #11
                      Re: modifying 'for... loop ' with php to leave out one number

                      "Ian Davies" <ian.dandav@vir gin.netwrote:
                      I also realised this too and have decides afterall to go with the if
                      statement by Miquel (THANKS MIQUEL) as there will be less lines of code. Do
                      you know if there is a performance advantage over the switch method?
                      I expect the 'if' method would be faster as there's less parsing and
                      testing.

                      miguel
                      --
                      Photos from 40 countries on 5 continents: http://travel.u.nu
                      Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
                      Airports of the world: http://airport.u.nu

                      Comment

                      • Marcin Dobrucki

                        #12
                        Re: modifying 'for... loop ' with php to leave out one number

                        Ian Davies wrote:
                        Hello
                        Im using the following loop to populate a list box but I dont want th
                        current selected value (from database) to show in the list
                        The one I want to omitt is in the variable
                        >
                        $row['bbannerorgfont ']
                        >
                        I wish to some how include this in the below loop to the effect of
                        >
                        echo from 0 to 6 except for $row['bbannerorgfont ']
                        >
                        VB has select...case.. . etc. Is there something similar with PHP?
                        create an array which contains the needed values*, then:

                        foreach ($array as $foo) {
                        echo '<option value="$foo">$f oo</option>';
                        }

                        * or have a default array and remove the unecessary ones.

                        Comment

                        Working...