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
Вопрос
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
<input type="radio" name="visible" value="1"<?php if($sel_subject['visible'] == 1) { echo " checked"; } ?>
/> Yes
Thank you.
Решение
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
Другие советы
<?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