php - How to order a MYSQL query by another query?
I am writing a PHP/MYSQL search function which takes a users search query (as a string) and matches it to records from a table by predefined fields and quantities (eg: bedrooms = 2, max_price < 100)
This is working fine, but now I want to order the results by a condition. So for example:
The users query is "2 Bedroom Penthouse"
The function matches records that have a value of 2 for the row bedrooms
I now want to keep the results that match, but order the results by the results that match for a description row with a value of "penthouse" (anywhere in the description string (which is a long string of lots of words))
I can match the results that have the word "penthouse" in the description, but what is the best way to order the results with the matched results first?
So, basically, how do you order results by another query?
Answer
Solution:
You don't. You write a more complex
ORDER BY
clause.(We invert the expression since false orders before true)