Problems related to loops of two associated tables

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.