0

I'm trying to display values of a radio button which are fetched from the database. I want to use it to update a subject in a blog i am developing so if an admin chooses to change its visibility. What i need now is to be able to show the visibility of the subject so that it could be changed. I am expecting this code to work but it didn't:

<p>Visible:
              <input type="radio" name="visible" value="0"<?php if($sel_subject['visible'] == 0) { echo " checked"; } ?>
              /> No
              &nbsp;
              <input type="radio" name="visible" value="1"<?php if($sel_subject['visible'] == 1) { echo " checked"; } ?>
              /> Yes

Thank you.

2 Answers 2

3

in short

<input type="radio" name="visible" value="0" <?=($sel_subject['visible'] == 0)?'checked':''?>/> No

<input type="radio" name="visible" value="0" <?=($sel_subject['visible'] == 1)?'checked':''?>/> Yes
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I just realised where my mistake is. I named a variable after I have another function that contains same variable. That's why it couldn't work.
1
<?php $sel_subject['visible'] = 0; ?>
<input type="radio" name="visible" value="0"<?php if($sel_subject['visible'] === 0) { echo " checked"; } ?>/> No
<input type="radio" name="visible" value="1"<?php if($sel_subject['visible'] == 1) { echo " checked"; } ?>/> Yes

<?php $sel_subject['visible'] = 1; ?>
<input type="radio" name="visible" value="0"<?php if($sel_subject['visible'] === 0) { echo " checked"; } ?>/> No
<input type="radio" name="visible" value="1"<?php if($sel_subject['visible'] == 1) { echo " checked"; } ?>/> Yes

Working Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.