while ($div=mysql_fetch_array($query4, MYSQL_ASSOC)) {
//$div - shows all the entries

$row22=mysql_fetch_array($query2, MYSQL_ASSOC);
//row22 - shows all the entries that should be checked...