This seems like a fairly straightfoward concept, but I can't seem to get mine to work, or find a good tutorial on it.
This is the basic skeleton of what I'm trying to do:
Table1:
table1_id,table1_disp
Table2:
table2_id,table1_id,table3_id
I populate an html table on a web page with all the values from table 1 with checkboxes next to them. What I want to do is have them default to being checked if they exist in table2 for that particular record.
So right now I have this, and it deffinitly doesn't work :o
$sql = "SELECT table1.tabl1_id, table1.table1_disp
FROM table1
WHERE table1.active_ind = '1'
ORDER BY 'table1_disp'";
$results = mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_array($results))
{
$table1_id = $row['table1_id'];
$mgr_sql = "SELECT table1_id,table3_id
FROM table2
WHERE table1_id = '".$row['table1_id']."' AND table3_id = '".$_GET['table3_id']."'";
$mgr_results = mysql_query($mgr_sql) or die(mysql_error());
while ($row2=mysql_fetch_array($mgr_results))
{
if ($row2['table1_id']==$table1_id)
{
$table1_checked = " CHECKED";
}else{
$table1_checked = "";
}
}
if ($nbrow % 5 === 0)
{
echo "</tr><tr>\n";
}
$nbrow++;
echo '<td class="tableleft">';
echo '<p align=right><input type="checkbox" value="'.$row['table1_id'].'"'.$table1_checked.' name="table[]">'.$row['table_disp'];
echo "\n";
}
Where am I going wrong (I realize it might be in quite a few places....)? Thanks!