开发者

How to Populate Checkbox?

I have two fields in my datab开发者_开发技巧ase and they are- name and user_id. I have a page called name.php where I have fives names and checkboxes for each of those names. Now what I want to do is when I visit the page “name.php”, I want names checked which are already inserted in the database. Would you please kindly help me to do this? Thanks in Advance


if the value in the db says it is checked you can add the checked attribute to the input element

<input type="checkbox" name="thename" checked="checked" />

so in your code it will be like:

<input type="checkbox" name="thename" <?php echo $value == 1 ? 'checked="checked"' : ''?> />

this will add the checked attribute if the value is equal to 1


Go over the records of the database, and when generating the chekboxes, see if the name appears in the database. If it does, add checked="checked" to the checkbox.

Working Example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜