简体   繁体   English

从内部的数据库数组中选择值复选框输入

[英]Select Value from DB Array inside check box input

Hello I am using various check boxes with different values and than storing the vales inside DataBase as all the checkboxes values are store inside Array 您好,我正在使用具有不同值的各种复选框,而不是将值存储在数据库中,因为所有复选框的值都存储在数组中

<input type="checkbox" value="Gym" id="details_10" name="utilities[]">
<input  type="checkbox" value="Spa" id="details_11" name="utilities[]">

and than store in the database like: Gym, Spa. 而不是存储在数据库中,例如:Gym,Spa。

Later I am making MySQL query inside edit form where I will be able to edit those and other parameters. 稍后,我将在编辑表单中进行MySQL查询,在其中我将能够编辑那些参数和其他参数。 For the other inputs I am using: 对于其他输入,我正在使用:

<?php if($row['data'] == 'Sample Data'){echo 'selected="selected"';}?>

In this case I would like to use something like the following: 在这种情况下,我想使用以下内容:

<input  type="checkbox" value="Gym" id="details_10" name="utilities[]"<?php if($row['utilities'] == 'Gym'){echo 'checked"';}?>>

Any help to achieve this result will be very welcome. 任何帮助实现此结果的帮助将非常受欢迎。

I've always used this in these cases. 在这些情况下,我一直使用此功能。

<?php
if($row['utilities'] == 'Gym')
{
    ?>
    <input  type="checkbox" value="Gym" id="details_10" name="utilities[]" checked="checked">
    <?php
}
else
{
    ?>
    <input  type="checkbox" value="Gym" id="details_10" name="utilities[]">
    <?php
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM