I have a form that's editable, but need some help displaying prechecked checkboxes.
I've simplified things for the example I'm about to use, but essentially, the tables I've set up are:
Colors_Table
ID | Color_Name
1 | red
2 | blue
3 |green
4 | yellow
And
Color_Management
ID | Color | Name
1 | red,blue | Joe
2| yellow, green | Sam
First, I want to build the array based on the values in the Colors_Table, so I use:
$query = "SELECT * FROM Colors_Table";
$result = @mysql_query($query);
$lookup_color = array();
while ($row = mysql_fetch_array ($result)) {
$ID = $row['ID'];
$lookup_color[$ID] = $row['Color_Name'];
}
Which works fine.
Then, I want to create checkboxes for Joe and precheck them according to his prior input. This is basically where I'm stuck.
I tried this:
$id = $_GET['id'];
$query = "SELECT * FROM Color_Management WHERE ID='$id'";
$result = @mysql_query($query);
while ($row=mysql_fetch_array($result)) {
$color_exp = explode(',',$row['Color']);
$colors = $row['Color'];
}
foreach ($lookup_color as $colors) {
if (in_array($colors,$color_exp)) {
$chk = 'checked';
} else {
$chk = '';
}
echo "<input type='checkbox' name='colors[]' value='$colors' $chk>$colors<br />";
}
(I also tried "switching" the order of $colors,$color_exp in the in_array, but that didn't work either)
But, I keep getting this error message:
Warning: in_array(): Wrong datatype for second argument