SELECT users.uid, users.profileImage, users.instid,
users.firstName, users.lastName, users.description,
GROUP_CONCAT(DISTINCT type.typename, ' '),
DEGREES(ACOS((SIN(RADIANS(?)) * SIN(RADIANS(users.latitude))
+ * COS(RADIANS(?)) * SIN(RADIANS(users.latitude)) * COS(RADIANS(? - users.longitude))))
) AS distance,
AVG(ratings.ratings) AS r
FROM users, ratings
JOIN connections ON connections.instid=users.instid
JOIN type ON type.typeid=connections.typeid OR type.typeName LIKE(?)
JOIN ratings ON ratings.instid=type.instid WHERE instructors.status=1 AND
(users.firstName LIKE(?) OR
users.lastName LIKE(?) OR
type.typeName LIKE(?) OR
GROUP BY users.instid
ORDER BY distance;
At some point, the people who previously worked on the code realized they could just do all their application logic in SQL. So they stopped writing PHP and let mySQL do the work for them.
Despite appearences, this isn’t a prepared statement.(That would have indicated some level of competence). Another file changes the ? into whatever varible they need to enter.
What does it do?
-Evaluate user’s distance from ?,?
-Shows average reviews(sort of)
-Only returns results that match search terms supplied by the client (At least that’s what I think, it only works if typename of the user is searched for)
Maybe they wanted to write the longest SQL query ever.