Hi,
I got two mysql tables.
First table, 'cat':
catid | name
------|------
1 | test
2 | bar
3 | foo
Second table, 'rel_groupcat':
groupid | catid
--------|-------
1 | 1
1 | 2
1 | 3
2 | 2
Then I got form with checkboxes. I want to check the box when the groupid had an entry for that catid:
<?
$cat = mysql_query("SELECT FROM cat");
$rel_groupcat = mysql_query("SELECT FROM rel_groupcat WHERE groupid='$group'");
/ $group comes from an other script /
while($cat_row = mysql_fetch_array($cat)) {
$rel_groupcat_row = mysql_fetch_array($rel_groupcat);
if($cat_row[id]==$rel_groupcat[catid]) {
$checked = "checked";
} else {
$checked = "";
}
echo "<input type="checkbox" value="cat_row[id]" $selected> $cat_row[name]";
}
This works ok for 'groupid = 1', but not for 'groupid = 2'!
Any hints? Thanks!