Search multiple rows

Hi, I hope someone can help as im really stuck on this now.

I have three columns called “grade_1” “grade_2” “grade_3”, In the search bar the user can select a grade from a drop down, i want the MySQL to search grade_1 if it doesn’t match try grade_2 , if it doesn’t match that try grade_3.

Ive tried using OR statement but it will always return 1. I’m fairly new to MySQL so any help would be great thanks

Ian

Ian,

Can you tell me a little more about your table and the query’s expected results?

Is something like this what you are looking to do:

Are you looking for something like this:
[table]
[tr]
[td]Student[/td][td]grade_1[/td][td]grade_2[/td][td]grade_3[/td]
[/tr]
[tr]
[td]Johnny[/td][td]D[/td][td]D[/td][td]A[/td]
[/tr]
[tr]
[td]Susie[/td][td]B[/td][td]A[/td][td]B[/td]
[/tr]
[/table]

“Find Johnny’s first A” -> grade_3
“Find Susie’s first A” -> grade_2

One of my multi field search where statement looks like this…

WHERE (Degrees_List.Status <> ‘2’)
AND (Types.type LIKE ‘%$q%’
OR Names.nname LIKE ‘%$q%’
OR Colleges.cname LIKE ‘%$q%’
OR Departments.dname LIKE ‘%$q%’
OR Degrees_List.ID LIKE ‘%$q%’
OR Types.name LIKE ‘%$q%’
OR Level.level LIKE ‘%$q%’)

Thanks so much for the reply, I changed my code a little and it works perfectly !!, I was missing the brackets and the LIKE part, are there any good websites etc you could recommend for learning more MySQL ?

Again, thanks alot !!

Ian

Sponsor our Newsletter | Privacy Policy | Terms of Service