How to display something from an array depending on users choice












0















I am trying to create a PHP program that has Select HTML options and an array with measurement. I would like to display a specific measure depending on the selection that they have made from the Select tag. Here is a picture of how I set up my website.

In addition, I have included a picture of all the selection options here.



$sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');


Overall what I want it to do is if a user selects the 2" x 12" option I would like for it to retrieve the proper measurement from the array, which would be 1-1/2" x 11-1/4 Here is what I would like it to display.



Currently this is how I have my Select tag setup



  <label> What size of lumber would you want?
<select name="size" required>
<option value="NULL"selected> -------- </option>
<option value="1"> 1" X 2" </option>
<option value="2"> 1" X 3" </option>
<option value="3"> 1" X 4" </option>
<option value="4"> 1" X 5" </option>
<option value="5"> 1" X 6" </option>
<option value="6"> 1" X 7" </option>
<option value="7"> 1" X 8" </option>
<option value="8"> 1" X 10" </option>
<option value="9"> 1" X 12" </option>
<option value="10"> 2" X 4" </option>
<option value="11"> 2" X 6" </option>
<option value="12"> 2" X 8" </option>
<option value="13"> 2" X 10" </option>
<option value="14"> 2" X 12" </option>
<option value="15"> 3" X 6" </option>
<option value="16"> 4" X 4" </option>
<option value="17"> 4" X 6" </option>
</select>
</label>


You guys may see that I have two submit buttons but for right now I'm trying to make sure that the inch one works first.



Let me know if you guys need more information or would like me to edit something.

Thank you for taking the time to try to help me out!










share|improve this question





























    0















    I am trying to create a PHP program that has Select HTML options and an array with measurement. I would like to display a specific measure depending on the selection that they have made from the Select tag. Here is a picture of how I set up my website.

    In addition, I have included a picture of all the selection options here.



    $sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');


    Overall what I want it to do is if a user selects the 2" x 12" option I would like for it to retrieve the proper measurement from the array, which would be 1-1/2" x 11-1/4 Here is what I would like it to display.



    Currently this is how I have my Select tag setup



      <label> What size of lumber would you want?
    <select name="size" required>
    <option value="NULL"selected> -------- </option>
    <option value="1"> 1" X 2" </option>
    <option value="2"> 1" X 3" </option>
    <option value="3"> 1" X 4" </option>
    <option value="4"> 1" X 5" </option>
    <option value="5"> 1" X 6" </option>
    <option value="6"> 1" X 7" </option>
    <option value="7"> 1" X 8" </option>
    <option value="8"> 1" X 10" </option>
    <option value="9"> 1" X 12" </option>
    <option value="10"> 2" X 4" </option>
    <option value="11"> 2" X 6" </option>
    <option value="12"> 2" X 8" </option>
    <option value="13"> 2" X 10" </option>
    <option value="14"> 2" X 12" </option>
    <option value="15"> 3" X 6" </option>
    <option value="16"> 4" X 4" </option>
    <option value="17"> 4" X 6" </option>
    </select>
    </label>


    You guys may see that I have two submit buttons but for right now I'm trying to make sure that the inch one works first.



    Let me know if you guys need more information or would like me to edit something.

    Thank you for taking the time to try to help me out!










    share|improve this question



























      0












      0








      0








      I am trying to create a PHP program that has Select HTML options and an array with measurement. I would like to display a specific measure depending on the selection that they have made from the Select tag. Here is a picture of how I set up my website.

      In addition, I have included a picture of all the selection options here.



      $sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');


      Overall what I want it to do is if a user selects the 2" x 12" option I would like for it to retrieve the proper measurement from the array, which would be 1-1/2" x 11-1/4 Here is what I would like it to display.



      Currently this is how I have my Select tag setup



        <label> What size of lumber would you want?
      <select name="size" required>
      <option value="NULL"selected> -------- </option>
      <option value="1"> 1" X 2" </option>
      <option value="2"> 1" X 3" </option>
      <option value="3"> 1" X 4" </option>
      <option value="4"> 1" X 5" </option>
      <option value="5"> 1" X 6" </option>
      <option value="6"> 1" X 7" </option>
      <option value="7"> 1" X 8" </option>
      <option value="8"> 1" X 10" </option>
      <option value="9"> 1" X 12" </option>
      <option value="10"> 2" X 4" </option>
      <option value="11"> 2" X 6" </option>
      <option value="12"> 2" X 8" </option>
      <option value="13"> 2" X 10" </option>
      <option value="14"> 2" X 12" </option>
      <option value="15"> 3" X 6" </option>
      <option value="16"> 4" X 4" </option>
      <option value="17"> 4" X 6" </option>
      </select>
      </label>


      You guys may see that I have two submit buttons but for right now I'm trying to make sure that the inch one works first.



      Let me know if you guys need more information or would like me to edit something.

      Thank you for taking the time to try to help me out!










      share|improve this question
















      I am trying to create a PHP program that has Select HTML options and an array with measurement. I would like to display a specific measure depending on the selection that they have made from the Select tag. Here is a picture of how I set up my website.

      In addition, I have included a picture of all the selection options here.



      $sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');


      Overall what I want it to do is if a user selects the 2" x 12" option I would like for it to retrieve the proper measurement from the array, which would be 1-1/2" x 11-1/4 Here is what I would like it to display.



      Currently this is how I have my Select tag setup



        <label> What size of lumber would you want?
      <select name="size" required>
      <option value="NULL"selected> -------- </option>
      <option value="1"> 1" X 2" </option>
      <option value="2"> 1" X 3" </option>
      <option value="3"> 1" X 4" </option>
      <option value="4"> 1" X 5" </option>
      <option value="5"> 1" X 6" </option>
      <option value="6"> 1" X 7" </option>
      <option value="7"> 1" X 8" </option>
      <option value="8"> 1" X 10" </option>
      <option value="9"> 1" X 12" </option>
      <option value="10"> 2" X 4" </option>
      <option value="11"> 2" X 6" </option>
      <option value="12"> 2" X 8" </option>
      <option value="13"> 2" X 10" </option>
      <option value="14"> 2" X 12" </option>
      <option value="15"> 3" X 6" </option>
      <option value="16"> 4" X 4" </option>
      <option value="17"> 4" X 6" </option>
      </select>
      </label>


      You guys may see that I have two submit buttons but for right now I'm trying to make sure that the inch one works first.



      Let me know if you guys need more information or would like me to edit something.

      Thank you for taking the time to try to help me out!







      php html5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 14:50









      Funk Forty Niner

      1




      1










      asked Nov 24 '18 at 14:48









      Guillermo Molina MatusGuillermo Molina Matus

      72




      72
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Once you submit the value of the select, you can then use it as the index of the array to retrieve the correct result from the array. It would look something like this.



          <?php
          //value of the select
          $selectValue = $_POST['size'];
          //your array with all possible values
          $sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');
          $displayResult = '';
          //traverse the array and find the selected index, after that break out of loop
          for ( $i = 0; $i < sizeof( $sizeInches ); $i++ ) {
          if ( $i === (int)$selectValue ) {
          $displayResult = $sizeInches[ $i ];
          break;
          }
          }
          ?>
          //display your result
          <h2> <?php echo $displayResult; ?></h2>


          I hope this helps you !






          share|improve this answer
























          • Thank you that worked!

            – Guillermo Molina Matus
            Nov 24 '18 at 15:58











          • Glad to be of help :)

            – BambiOurLord
            Nov 24 '18 at 15:59



















          0














          <?php
          $selectValue=$_POST['size'];
          $displayResult = '';
          foreach($sizeInches as $Inches )
          {
          if( $Inches== $selectValue )
          {
          print_r($Inches);
          break;
          }
          }
          ?>





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459326%2fhow-to-display-something-from-an-array-depending-on-users-choice%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Once you submit the value of the select, you can then use it as the index of the array to retrieve the correct result from the array. It would look something like this.



            <?php
            //value of the select
            $selectValue = $_POST['size'];
            //your array with all possible values
            $sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');
            $displayResult = '';
            //traverse the array and find the selected index, after that break out of loop
            for ( $i = 0; $i < sizeof( $sizeInches ); $i++ ) {
            if ( $i === (int)$selectValue ) {
            $displayResult = $sizeInches[ $i ];
            break;
            }
            }
            ?>
            //display your result
            <h2> <?php echo $displayResult; ?></h2>


            I hope this helps you !






            share|improve this answer
























            • Thank you that worked!

              – Guillermo Molina Matus
              Nov 24 '18 at 15:58











            • Glad to be of help :)

              – BambiOurLord
              Nov 24 '18 at 15:59
















            0














            Once you submit the value of the select, you can then use it as the index of the array to retrieve the correct result from the array. It would look something like this.



            <?php
            //value of the select
            $selectValue = $_POST['size'];
            //your array with all possible values
            $sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');
            $displayResult = '';
            //traverse the array and find the selected index, after that break out of loop
            for ( $i = 0; $i < sizeof( $sizeInches ); $i++ ) {
            if ( $i === (int)$selectValue ) {
            $displayResult = $sizeInches[ $i ];
            break;
            }
            }
            ?>
            //display your result
            <h2> <?php echo $displayResult; ?></h2>


            I hope this helps you !






            share|improve this answer
























            • Thank you that worked!

              – Guillermo Molina Matus
              Nov 24 '18 at 15:58











            • Glad to be of help :)

              – BambiOurLord
              Nov 24 '18 at 15:59














            0












            0








            0







            Once you submit the value of the select, you can then use it as the index of the array to retrieve the correct result from the array. It would look something like this.



            <?php
            //value of the select
            $selectValue = $_POST['size'];
            //your array with all possible values
            $sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');
            $displayResult = '';
            //traverse the array and find the selected index, after that break out of loop
            for ( $i = 0; $i < sizeof( $sizeInches ); $i++ ) {
            if ( $i === (int)$selectValue ) {
            $displayResult = $sizeInches[ $i ];
            break;
            }
            }
            ?>
            //display your result
            <h2> <?php echo $displayResult; ?></h2>


            I hope this helps you !






            share|improve this answer













            Once you submit the value of the select, you can then use it as the index of the array to retrieve the correct result from the array. It would look something like this.



            <?php
            //value of the select
            $selectValue = $_POST['size'];
            //your array with all possible values
            $sizeInches = array('3/4" x 1-1/2"', '3/4” x 2-1/2”','3/4” x 3-1/2”', '3/4” x 4-1/2”', '3/4” x 5-1/2”', '3/4” x 6-1/4”', '3/4” x 7-1/4”', '3/4" x 9-1/4"', '3/4" x 9-1/4"', '3/4" x 11-1/4"', '1-1/2" x 3-1/2"', '1-1/2" x 5-1/2"', '1-1/2" x 7-1/4"', '1-1/2" x 9-1/4"', '1-1/2" x 11-1/4"', '2-1/2" x 5-1/2"', '3-1/2" x 3-1/2"', '3-1/2" x 5-1/2"');
            $displayResult = '';
            //traverse the array and find the selected index, after that break out of loop
            for ( $i = 0; $i < sizeof( $sizeInches ); $i++ ) {
            if ( $i === (int)$selectValue ) {
            $displayResult = $sizeInches[ $i ];
            break;
            }
            }
            ?>
            //display your result
            <h2> <?php echo $displayResult; ?></h2>


            I hope this helps you !







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 24 '18 at 15:19









            BambiOurLordBambiOurLord

            310310




            310310













            • Thank you that worked!

              – Guillermo Molina Matus
              Nov 24 '18 at 15:58











            • Glad to be of help :)

              – BambiOurLord
              Nov 24 '18 at 15:59



















            • Thank you that worked!

              – Guillermo Molina Matus
              Nov 24 '18 at 15:58











            • Glad to be of help :)

              – BambiOurLord
              Nov 24 '18 at 15:59

















            Thank you that worked!

            – Guillermo Molina Matus
            Nov 24 '18 at 15:58





            Thank you that worked!

            – Guillermo Molina Matus
            Nov 24 '18 at 15:58













            Glad to be of help :)

            – BambiOurLord
            Nov 24 '18 at 15:59





            Glad to be of help :)

            – BambiOurLord
            Nov 24 '18 at 15:59













            0














            <?php
            $selectValue=$_POST['size'];
            $displayResult = '';
            foreach($sizeInches as $Inches )
            {
            if( $Inches== $selectValue )
            {
            print_r($Inches);
            break;
            }
            }
            ?>





            share|improve this answer






























              0














              <?php
              $selectValue=$_POST['size'];
              $displayResult = '';
              foreach($sizeInches as $Inches )
              {
              if( $Inches== $selectValue )
              {
              print_r($Inches);
              break;
              }
              }
              ?>





              share|improve this answer




























                0












                0








                0







                <?php
                $selectValue=$_POST['size'];
                $displayResult = '';
                foreach($sizeInches as $Inches )
                {
                if( $Inches== $selectValue )
                {
                print_r($Inches);
                break;
                }
                }
                ?>





                share|improve this answer















                <?php
                $selectValue=$_POST['size'];
                $displayResult = '';
                foreach($sizeInches as $Inches )
                {
                if( $Inches== $selectValue )
                {
                print_r($Inches);
                break;
                }
                }
                ?>






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 24 '18 at 22:03









                Nic3500

                3,34081829




                3,34081829










                answered Nov 24 '18 at 20:16









                Piermarcello PiazzaPiermarcello Piazza

                1




                1






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459326%2fhow-to-display-something-from-an-array-depending-on-users-choice%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen