Jump to content


Help With Query to Multiple Tables

  • Please log in to reply
2 replies to this topic

#1 bobbyv102

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 19 June 2006 - 06:32 AM


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.


#2 klaroen

  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 19 June 2006 - 06:52 AM

I think you just need to do a few queries...

#3 radalin

  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 19 June 2006 - 08:19 AM

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?
Roy Simkes
Yet Another Parkyeri Developer

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users