Skip to content
Advertisement

Need to fix sorting order by name and price

I am working on school listing project. I have created database name is school and under I add new table name is schoollist Here I have many school. I have added few column on it bellow the list of column.

For the above table i want to search Wright Oslo and after the result should be Wright oslo school and Wright school because Wright oslo school have low price. And other school dont need show because of they dont have exact name school of wright. How can i get it done by sql query I used old query but its not working perfectly bellow the code:

I want output should be like bellow:

Advertisement

Answer

Using the same dataset as yours :

enter image description here

You can achieve your goal using this query :

Here is the result as expected :

enter image description here

  1. You order by price (ASC by default)

  2. You search for any match with the keywords (Wright and Oslo), even if they are not stuck together. Once you get the user input, you have to string replace any whitespace with the % caracter and to add % at the beginning and at the end of the input :

  3. For security purposes, you should use a prepared statement :

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement