Link to home
Start Free TrialLog in
Avatar of Mlungisi Ndlela
Mlungisi NdlelaFlag for South Africa

asked on

How to sort with a mysql column

Hi EE.

I have a query that retrieve data that has the provided word and this works well but now I want to sort this data when being retrieved based on a column name `lp` but I don't seem to be able to do so as if I add the Order by then the query seems not to return anything as the row is returned with 0. Below is the query code that I'm referring to here.
$querrry = "SELECT * FROM `xxxxdatabase`.`xxxxtable`  WHERE tags LIKE '%$searchq%' OR name LIKE '%$searchq%' OR category LIKE '%$searchq%' OR username LIKE '%$searchq%' OR addr2 LIKE '%$searchq%' OR city LIKE '%$searchq%' OR province LIKE '%$searchq' OR country LIKE '%$searchq%' OR company LIKE '%$searchq%' LIMIT 0,10 ORDER BY lp ASC " or die(mysqli_error());
$resultz = mysqli_query($conn, $querrry);

Open in new window


I'm using Mysqli.
Avatar of Peter Schultz
Peter Schultz
Flag of Germany image

hmm is that field Ip numeric ? Then try IsNum ... ORDER BY lp IsNum " or ....
Avatar of Mlungisi Ndlela

ASKER

I've just tried that but still the row is returned with 0 which means there was no search.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Chris is right, MySQL is very picky about the order of the statements in a query.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial