Return the value of 0 and 1 from database to No / Yes in a select box












2















In my database I have the column 'pe' with the value of 0 or 1.



0 equaling No/false and 1 equaling Yes/true.



How can I show the users the output of Yes or No instead of 0 or 1 based on there choice in the select box below?



Here is a picture of what the form currently looks like.
Current Form



I would like the 1 to display Yes and the 0 to display No in the select box.
Just not sure how to do this since it's pulling the value from the database table.



I know an easy workaround would be to write "Please choose", instead of outputting the value, but I want the user(s) to see what they have already chosen.



Here is my code snippet.



<label for="pe">Would you like to make your Email public?</label>
<select name="pe">
<option value="<?php echo escape($user->data()->pe); ?>"><?php echo escape($user->data()->pe); ?></option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>









share|improve this question



























    2















    In my database I have the column 'pe' with the value of 0 or 1.



    0 equaling No/false and 1 equaling Yes/true.



    How can I show the users the output of Yes or No instead of 0 or 1 based on there choice in the select box below?



    Here is a picture of what the form currently looks like.
    Current Form



    I would like the 1 to display Yes and the 0 to display No in the select box.
    Just not sure how to do this since it's pulling the value from the database table.



    I know an easy workaround would be to write "Please choose", instead of outputting the value, but I want the user(s) to see what they have already chosen.



    Here is my code snippet.



    <label for="pe">Would you like to make your Email public?</label>
    <select name="pe">
    <option value="<?php echo escape($user->data()->pe); ?>"><?php echo escape($user->data()->pe); ?></option>
    <option value="1">Yes</option>
    <option value="0">No</option>
    </select>









    share|improve this question

























      2












      2








      2


      1






      In my database I have the column 'pe' with the value of 0 or 1.



      0 equaling No/false and 1 equaling Yes/true.



      How can I show the users the output of Yes or No instead of 0 or 1 based on there choice in the select box below?



      Here is a picture of what the form currently looks like.
      Current Form



      I would like the 1 to display Yes and the 0 to display No in the select box.
      Just not sure how to do this since it's pulling the value from the database table.



      I know an easy workaround would be to write "Please choose", instead of outputting the value, but I want the user(s) to see what they have already chosen.



      Here is my code snippet.



      <label for="pe">Would you like to make your Email public?</label>
      <select name="pe">
      <option value="<?php echo escape($user->data()->pe); ?>"><?php echo escape($user->data()->pe); ?></option>
      <option value="1">Yes</option>
      <option value="0">No</option>
      </select>









      share|improve this question














      In my database I have the column 'pe' with the value of 0 or 1.



      0 equaling No/false and 1 equaling Yes/true.



      How can I show the users the output of Yes or No instead of 0 or 1 based on there choice in the select box below?



      Here is a picture of what the form currently looks like.
      Current Form



      I would like the 1 to display Yes and the 0 to display No in the select box.
      Just not sure how to do this since it's pulling the value from the database table.



      I know an easy workaround would be to write "Please choose", instead of outputting the value, but I want the user(s) to see what they have already chosen.



      Here is my code snippet.



      <label for="pe">Would you like to make your Email public?</label>
      <select name="pe">
      <option value="<?php echo escape($user->data()->pe); ?>"><?php echo escape($user->data()->pe); ?></option>
      <option value="1">Yes</option>
      <option value="0">No</option>
      </select>






      php






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 28 '14 at 14:59









      echoecho

      524825




      524825
























          3 Answers
          3






          active

          oldest

          votes


















          1














          Assuming <?php echo escape($user->data()->pe); ?> is what returns 0 or 1, simply use a ternary if statement:



          <?php echo escape($user->data()->pe) == "1" ? "Yes" : "No"; ?>





          share|improve this answer



















          • 1





            Thank you that totally worked and was exactly what I was looking for. Thanks again!

            – echo
            May 28 '14 at 15:04



















          1














          Assuming $user->data()->pe has the value 0 or 1

          You can place the selected attribute on the option with that value.



          <option value="1"<?php echo ($user->data()->pe == 1)?' selected':''; ?>>Yes</option>
          <option value="0"<?php echo ($user->data()->pe == 0)?' selected':''; ?>>No</option>





          share|improve this answer
























          • That also worked very well. Thank you for showing me this method as well. Didn't realize there were a couple ways to do this.

            – echo
            May 28 '14 at 15:14



















          0














          Suppose if $data->value has the value 0 or 1



          <input type="radio" value="yes" <?php if ($data->value=="1"){echo 'selected';}?> name="name" value="yes"> Yes
          <input type="radio" value="no" <?php if ($data->value=="0"){echo 'selected';}?> name="name" value="no"> No





          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%2f23915162%2freturn-the-value-of-0-and-1-from-database-to-no-yes-in-a-select-box%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Assuming <?php echo escape($user->data()->pe); ?> is what returns 0 or 1, simply use a ternary if statement:



            <?php echo escape($user->data()->pe) == "1" ? "Yes" : "No"; ?>





            share|improve this answer



















            • 1





              Thank you that totally worked and was exactly what I was looking for. Thanks again!

              – echo
              May 28 '14 at 15:04
















            1














            Assuming <?php echo escape($user->data()->pe); ?> is what returns 0 or 1, simply use a ternary if statement:



            <?php echo escape($user->data()->pe) == "1" ? "Yes" : "No"; ?>





            share|improve this answer



















            • 1





              Thank you that totally worked and was exactly what I was looking for. Thanks again!

              – echo
              May 28 '14 at 15:04














            1












            1








            1







            Assuming <?php echo escape($user->data()->pe); ?> is what returns 0 or 1, simply use a ternary if statement:



            <?php echo escape($user->data()->pe) == "1" ? "Yes" : "No"; ?>





            share|improve this answer













            Assuming <?php echo escape($user->data()->pe); ?> is what returns 0 or 1, simply use a ternary if statement:



            <?php echo escape($user->data()->pe) == "1" ? "Yes" : "No"; ?>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 28 '14 at 15:02









            James DonnellyJames Donnelly

            101k22157174




            101k22157174








            • 1





              Thank you that totally worked and was exactly what I was looking for. Thanks again!

              – echo
              May 28 '14 at 15:04














            • 1





              Thank you that totally worked and was exactly what I was looking for. Thanks again!

              – echo
              May 28 '14 at 15:04








            1




            1





            Thank you that totally worked and was exactly what I was looking for. Thanks again!

            – echo
            May 28 '14 at 15:04





            Thank you that totally worked and was exactly what I was looking for. Thanks again!

            – echo
            May 28 '14 at 15:04













            1














            Assuming $user->data()->pe has the value 0 or 1

            You can place the selected attribute on the option with that value.



            <option value="1"<?php echo ($user->data()->pe == 1)?' selected':''; ?>>Yes</option>
            <option value="0"<?php echo ($user->data()->pe == 0)?' selected':''; ?>>No</option>





            share|improve this answer
























            • That also worked very well. Thank you for showing me this method as well. Didn't realize there were a couple ways to do this.

              – echo
              May 28 '14 at 15:14
















            1














            Assuming $user->data()->pe has the value 0 or 1

            You can place the selected attribute on the option with that value.



            <option value="1"<?php echo ($user->data()->pe == 1)?' selected':''; ?>>Yes</option>
            <option value="0"<?php echo ($user->data()->pe == 0)?' selected':''; ?>>No</option>





            share|improve this answer
























            • That also worked very well. Thank you for showing me this method as well. Didn't realize there were a couple ways to do this.

              – echo
              May 28 '14 at 15:14














            1












            1








            1







            Assuming $user->data()->pe has the value 0 or 1

            You can place the selected attribute on the option with that value.



            <option value="1"<?php echo ($user->data()->pe == 1)?' selected':''; ?>>Yes</option>
            <option value="0"<?php echo ($user->data()->pe == 0)?' selected':''; ?>>No</option>





            share|improve this answer













            Assuming $user->data()->pe has the value 0 or 1

            You can place the selected attribute on the option with that value.



            <option value="1"<?php echo ($user->data()->pe == 1)?' selected':''; ?>>Yes</option>
            <option value="0"<?php echo ($user->data()->pe == 0)?' selected':''; ?>>No</option>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 28 '14 at 15:05









            MusaMusa

            80.7k1588106




            80.7k1588106













            • That also worked very well. Thank you for showing me this method as well. Didn't realize there were a couple ways to do this.

              – echo
              May 28 '14 at 15:14



















            • That also worked very well. Thank you for showing me this method as well. Didn't realize there were a couple ways to do this.

              – echo
              May 28 '14 at 15:14

















            That also worked very well. Thank you for showing me this method as well. Didn't realize there were a couple ways to do this.

            – echo
            May 28 '14 at 15:14





            That also worked very well. Thank you for showing me this method as well. Didn't realize there were a couple ways to do this.

            – echo
            May 28 '14 at 15:14











            0














            Suppose if $data->value has the value 0 or 1



            <input type="radio" value="yes" <?php if ($data->value=="1"){echo 'selected';}?> name="name" value="yes"> Yes
            <input type="radio" value="no" <?php if ($data->value=="0"){echo 'selected';}?> name="name" value="no"> No





            share|improve this answer






























              0














              Suppose if $data->value has the value 0 or 1



              <input type="radio" value="yes" <?php if ($data->value=="1"){echo 'selected';}?> name="name" value="yes"> Yes
              <input type="radio" value="no" <?php if ($data->value=="0"){echo 'selected';}?> name="name" value="no"> No





              share|improve this answer




























                0












                0








                0







                Suppose if $data->value has the value 0 or 1



                <input type="radio" value="yes" <?php if ($data->value=="1"){echo 'selected';}?> name="name" value="yes"> Yes
                <input type="radio" value="no" <?php if ($data->value=="0"){echo 'selected';}?> name="name" value="no"> No





                share|improve this answer















                Suppose if $data->value has the value 0 or 1



                <input type="radio" value="yes" <?php if ($data->value=="1"){echo 'selected';}?> name="name" value="yes"> Yes
                <input type="radio" value="no" <?php if ($data->value=="0"){echo 'selected';}?> name="name" value="no"> No






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 23 '17 at 15:51

























                answered Dec 21 '17 at 9:45









                Abhilash SharmaAbhilash Sharma

                165




                165






























                    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%2f23915162%2freturn-the-value-of-0-and-1-from-database-to-no-yes-in-a-select-box%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

                    MongoDB - Not Authorized To Execute Command

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                    Npm cannot find a required file even through it is in the searched directory