1

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.

Later I am making MySQL query inside edit form where I will be able to edit those and other parameters. 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.

1 Answer 1

1

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
}
?>
Sign up to request clarification or add additional context in comments.

4 Comments

The problem is that utilities is an array something like that: Gym, Spa, ... It is not a single value. So the problem is how to say if some of the values in this array is Gym than yes echo checked="checked"
Do a var_dump of your array and post here/
2 Parqueos, Area de niños
okay I made it work like this : (strpos($row['utilities_spanish'],'Area de niños') !== false) thanks for your help !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.