Ok, hopefully this will make my problem clearer.
$q2 = "SELECT *
FROM contactxprogrammes c, programmes p
WHERE c.contact_code = '$contact_code'
AND c.prog_code = p.prog_code
GROUP BY p.prog_name
";
$rslt = mysql_query($q2);
while($row2 = mysql_fetch_array($rslt)) {
echo "<p>";
echo "<input type=\"checkbox\" name=\"programmes[]\" value=\"".$row2['prog_code']."\" checked>".$row2['prog_name']."";
echo "</p>";
$q3 = "SELECT *
FROM programmes
WHERE prog_name != '$row2[prog_name]'
ORDER BY prog_name
";
$rslt3 = mysql_query($q3);
while($row3 = mysql_fetch_array($rslt3)){
echo "<p>";
echo "<input type=\"checkbox\" name=\"programmes[]\" value=\"$prog_code\">".$row3['prog_name']."";
echo "</p>";
}
}
What i need to do is display results from 2 tables programmes ( which is just a list of all programmes in the table .) And contactxprogrammes ( which is a table where programmes that have been previously checked are stored. )
In my code i want to show all programmes but i also need to look into the contactxprogrammes table to see if any programmes have been checked for this record. If they have then i want to programme check box to be checked, if not then just display as unchecked.
I either get all or nothing in my results or what i'm getting with the above code is repetition of all the programmes to the number of items in the contactxprogrammes table ( which is caused by the loop ) and i really don't know how to prevent this.
Thanks again