Using two tables

I have 2 tables Im retrieving records from.

The first table(lessons) contains a list of lessons for a student to view. I have a second table(progress that logs all the lessons the student already watched. I want to be able to list everything in LESSONS but create check marks next to each row according to what PROGRESS is showing me.

How would I construct the code in PHP.
Here is my solution so far:

        select everything from lessons

        foreach($result as $row) {
                echo "<tr class=\"lessons-row\">";     
                echo "<td class=\"ltitle\" >" . $row['title'] . "</td>";
                select everything from PROGRESS table
                loop through PROGRESS table and find record
                      if record has check mark
                             echo "<td>checked code</td>";
                      else
                             echo "<td>not checked code</td>";
                      }     
                echo "</tr>";      
            
        }

You would use a single LEFT JOIN query between the lessons and progress table. The any field you include in the SELECT term from the 2nd table will be a null (false) value if there’s no corresponding row in the 2nd table.

1 Like

thank you…will I then be able to access the value of CHECKED in the second progress table…regardless of what that value is.

Sponsor our Newsletter | Privacy Policy | Terms of Service