Hi,
I'm trying to show a list of checkboxes, where some are unchecked, depending on if they are not in one of the 2 tables (table2). I have managed to do this in other cases, but only when one of the tables had a fixed number of rows. Can anyone show some light on this? THX 🙂
This is my code, it produces a list of all found rows in table 1, all checked, minus the one that is missing in table 2, instead of showing all found rows in table 1, with the missing row in table 2 showing as unchecked:
dbsystem();
$prod = $row2['subcat_id'];
$charge = $row2['cat_id'];
$query = "
SELECT DISTINCT
table1.raw,
table2.roh
FROM
table1
LEFT JOIN
table2
ON
table1.prod = '$prod'
WHERE
table1.raw = table2.roh
AND
table1.prod = table2.id
ORDER BY
table2.roh
";
$raw = array();
$result=mysql_query($query);
while($row = mysql_fetch_row($result)){
$raw[] = $row;
}
$counter = 0;
$w = count($raw);
for($i = 0; $i < $w; $i++) {
if(!empty($raw[$counter])) {
if($raw[$counter][1] != '') {
$checked = ("checked");
} else {
$checked = ("");
}
echo("<div style=\"clear:both\"><div style=\"width:146px;float:left\"><input type=\"checkbox\" name=\"raw[]\" value=\"".$raw[$counter][0]."\" ".$checked." /> ".$raw[$counter][0]."-".$raw[$counter][1]."</div><div style=\"width:125px;float:left\">".$raw[$counter][1]."</div></div>\n");
}
$counter++;
}