There are two associated table loops. I now have two database tables. the curriculum is subjectidsubjectname1 language 2 Mathematics 3 the curriculum selected by the English class classsubjectidclassid (class Table id) subjectid (course table id) 11 loop problem of two associated tables
I now have two database tables
Course list subject
Id subjectname
1 Language
2. Mathematics
3 English
Classsubject
Id classid (class Table id) subjectid (course table id)
1 1 1
2 1 2
3 1 1
I need to display all the courses in the curriculum in the form of check boxes on the implementation page.
Then, the corresponding course id is queried based on the class id, and the corresponding course check box is selected.
If the class id is 1
The page is displayed as follows:
HTML code
ChineseMathematicsEnglish
How should we implement it? let's look at it.
------ Solution --------------------
SQL code
SELECT s. *, c. subjectid FROM subject AS s left join classsubject AS c ON s. id = c. subjectid AND c. classid = 1
------ Solution --------------------
Use the first-floor query to find the array of all selected courses in the class, and then query the array of all courses. two foreach loops are nested (there may be other better methods) you can mark the selected course arrays and output them cyclically.