I have three columns -- Use | City | School
In cities where the school is just the name of the city, city is NULL. In cities that have multiple schools or the name of the school isn't *just* the name of the city I fill in the city name, but the name of the city isn't always incorporated into the school name.
On the right hand side of the page, it prints:
It should read:
(I have a trigger that determines when to print the city into the name and when not to.)
The data table columns look like this (I struck out the city names not being used in printing the school name)
Use | City | School
0 | NULL | Kokomo
0 | NULL | Logansport
0 | NULL | Marion
1 | Lafayette | Jefferson
0 | Lafayette | McCutcheon
0 | West Lafayette | Harrison
The query is actually looking for the teams in the same Sectional (bsect) as the featured school -- in the linked case above, McCutcheon.
$query = "SELECT use,city,school from a_schools as s1
LEFT JOIN a_schools as s2
ON s1.bsect = s2.bsect
WHERE '" . $query_school . "' = CONCAT(s1.city,' ',s1.school) || '" . $query_school . "' = s1.school
ORDER BY concat(s2.city,s2.school) asc";
(The WHERE has to look for examples where it's just the school name OR examples where the city is incorporated in the school name.)
In a lot of instances, how I have this ordered works, which is why I have it that way, but this is definitely an example where it doesn't.
Do I wait to sort after the query?