Oct 24, 2009
I am trying to display records from my mysql database base on 3 variables (surname, quizname & class) user enter into a form. The problem I have is, I want users to be able to enter 1,2, or 3 values and then search accordingly (e.g. they could enter values into 1 & 2, 1 & 3, 1,2 & 3 etc). I can only get it to work for a fixed amount and I want it to be flexible. My code which works for 2 variables (var_name & var_class) is below. But it only works if both fields have been entered. I think I need a way of checking if the variable is default value and then use suitable where clause but I can’t figure it out.
View 6 Replies
SELECT tblUserDetails.Surname, tblUserDetails.Forename, tblScore.Quizname, tblScore.UserScore, tblUserDetails.Class
FROM tblUserDetails, tblScore
WHERE tblScore.Username = tblUserDetails.Username AND tblUserDetails.Class = var_class AND tblUserDetails.Surname = var_name