OK, there are two obvious errors:
COALESCE()
will always return the first param, which is not null (in your case always the value stored inco_subj1
)- the second SQL-query does not include any
WHERE
-clause. Because of this you getco_subj1
of all courses
While probably not the best solution possible, this should work:
$select = select("SELECT * FROM course_conf JOIN course_type ON ct_id=co_fk_ct_id ORDER BY co_name");
while($registroBbdd = consultaRegistro($select))
{
$courseName = $registroBbdd['co_name'];
echo '<div class="contentColumn80">
<span class="tableContentText ">'.$courseName.' - </span>';
for($i = 1; $i <= 12; $i++)
{
if($registroBbdd['co_subj'.$i] != null) {
echo '<span>CURSO: ' . $registroBbdd['co_subj'.$i] . ' - </span>';
}
}
echo '</div>';
}