Jump to content


This topic is now archived and is closed to further replies.


Help With Query to Multiple Tables

Recommended Posts


As the post states I am fairly new to PHP. I am working on a database in MS SQL and what I am trying to do is use a PHP web page to pull data from it. The original script works to pull from one table, but now I need it to pull from 3 seperate tables.

The database stores:

1. list of instructors = tblInstructors
-Instructor id = eeid
- instructor first name = fname
- instructor last name = lname
2. list of Classes = tblSchedule
-Course id = id
- instructor name = fname
- start date = Date
-end date = EndDate
3. the survey responses = tblPostClassSurvey
- 12 different survey question fields
- survey id = id
- course id = CourseID

I need all the results from post class survey, but only of the name of the instructor which is stored in the php variable $instructor, and the date grouped by the date. Unfortunately I do not have the code I have used so far here at home, but a point in the right direction will help. I found several resources that used the join option and pulling my fields with dot notation (ie: tblSchedule.id) but that does not return anything. Any help woul dbe great help.


Share this post

Link to post
Share on other sites
It's more then a database question then a php problem I think. You could use a query like:

SELECT tb1.id,tb2.id,tb3.id FROM tb1,tb2,tb3 WHERE tb1.id=tb2.id
where in this code tb1 stands for table names. You could use such a query. Or It seems that you have some where clauses which use some values pulled from db. You could such a query:
SELECT id FROM tb1 WHERE id IN ( SELECT id FROM tb2 WHERE id IN ( SELECT id FROM tb3 WHERE fname='myname' ) )
id will take values which the in statement returns and if our in statement return 2 and 3 our code will be like:
SELECT id FROM tb1 WHERE id = 2 OR id = 3

Is this helps?

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.