Hi there - I have a php page that pulls data from a db of courses cross referenced against a schedule table so that I get a series of table rows printed out containing the dates when those courses are running.
The page is designed to show 6 months of the year at a time.
The current sql works fine if the course has a course date in every month from jan to jun or jul to dec but on some occasions the course might not run one particular month. My sql query only finds courses where a course has dates in a particular month, any gaps are ignored. Therefore the loop that uses this data to print out a line of dates doesn't 100% work because there are no gaps in the RS.
An example is where a course has dates in Jul, Aug, Sept, Oct, Nov, Dec - 6 columns are written out. If there is no date for Oct, only 5 cols of data are returned and my loop incorrectly runs only five times.
So the solution to my problem is to convert my existing query to use LEFT JOINs as these will return nulls and these I can detect and use in my loop to write out a blank cell when required.
Now my problem -
$getDatesAssociatedWithThisCourse = "SELECT tblCourses.courseID, tblCourses.duration, tblSchedule.day, tblSchedule.monthID, tblSchedule.yearID, tblYear.year
FROM tblCourses, tblSchedule, tblYear, tblMonth
WHERE tblCourses.courseID = tblSchedule.courseID
AND tblSchedule.yearID = tblYear.yearID
AND tblSchedule.monthID = tblMonth.monthID
AND tblCourses.courseID = ".$link."
AND tblMonth.monthID = ".$idx." ORDER BY monthID ASC";
Here is my original query. Can anyone provide any tips on how to convert this to one that is LEFT JOIN based? I can only find examples that use two tables, not multiple ones, especially where in some cases vars are added to the sql.