I have a School database with two courses, each course has 12 possible subject fields (co_subj...
) that can contain the subject ID or NULL, in this case course ID 1 has 3 subjects, and course 2 has only 1:
I need PHP to create a <div>
for each subject found on a course, and don't create nothing in any NULL case. Querys:
$select = mysql_query("SELECT * FROM course_conf JOIN course_type ON ct_id=co_fk_ct_id ORDER BY co_name");
And then a while makes PHP check every course's field:
while($registroBbdd = mysql_fetch_array($select))
{
$class="";
$courseId=$registroBbdd['co_id'];
$courseName=$registroBbdd['co_name'];
$courseType=$registroBbdd['ct_name'];
The doubt comes right now, trying to solve the most efficient way the <div>
creating I mentioned before. The only way I find to solve this is creating a conditional "IF" structure printing the if a value is found, and nothing if NULL is found, like this:
if($registroBbdd['co_subj1'] != NULL){
echo "<div>'.$registroBbdd['co_subj1'].'</div>}
else if ($registroBbdd['co_subj2'] != NULL){
echo "<div>'.$registroBbdd['co_subj2'].'</div>}
.............}
Is there any looping way to make this? In order to avoid the whole "if" structure creation.