Return the value of 0 and 1 from database to No / Yes in a select box
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
add a comment |
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
add a comment |
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
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
php
asked May 28 '14 at 14:59


echoecho
524825
524825
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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"; ?>
1
Thank you that totally worked and was exactly what I was looking for. Thanks again!
– echo
May 28 '14 at 15:04
add a comment |
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>
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
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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"; ?>
1
Thank you that totally worked and was exactly what I was looking for. Thanks again!
– echo
May 28 '14 at 15:04
add a comment |
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"; ?>
1
Thank you that totally worked and was exactly what I was looking for. Thanks again!
– echo
May 28 '14 at 15:04
add a comment |
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"; ?>
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"; ?>
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
add a comment |
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
add a comment |
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Dec 23 '17 at 15:51
answered Dec 21 '17 at 9:45
Abhilash SharmaAbhilash Sharma
165
165
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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