Hello all,
I’ll building a database for a school, here’s my query:
SELECT *, DATE_ADD(students.dob, INTERVAL -students.year_advancement YEAR) AS dobaltered FROM students
WHERE school = '$school' AND @dobaltered > $marker
ORDER BY dobaltered DESC, surname ASC
LIMIT $pgOffset, $numPerPage
The DATE_ADD functions accounts for students who have been put forward in the school year. The value of year_advancement is therefore between 0-3.
Each student has his/her date of birth entered (dob). The database is for students within year groups 7-11. All students entered into the database are year 7 at a minimum. However, as soon as they reach year 12 their details are to be kept but not displayed. I therefore want to dis-include students who are too old.
From what I’ve read, it seems my problem is that my variable ‘dobaltered’ is created during the SELECT clause, however this is executed after the WHERE part of the query?
‘$marker’ is a PHP variable - it’s the cut-off point date.
Any help would be greatly appreciated.
Thanks