kanala Posted April 4, 2008 Share Posted April 4, 2008 How do I change the ORDER BY of a search query?Example $query = "SELECT * FROM products WHERE Item_name LIKE $ItemName ORDER BY Item_name";When clicking a link, how do I change it so that it changes to ORDER BY Price? Link to comment Share on other sites More sharing options...
Lulzim Posted April 4, 2008 Share Posted April 4, 2008 in html create links like this Order by: <a href='?orderby=Item_name'>Item name</a> <a href='?orderby=Price'>Price</a> then modify the php code $query = "SELECT * FROM products WHERE Item_name LIKE $ItemName ORDER BY ".$_GET['orderby']; and make sure to check the $_GET for any dangerous character before passing it to the query Link to comment Share on other sites More sharing options...
Synook Posted April 5, 2008 Share Posted April 5, 2008 and make sure to check the $_GET for any dangerous character before passing it to the queryE.g. with mysql_real_escape_string() or with a Regex such as /$[a-z]^/i Link to comment Share on other sites More sharing options...
kanala Posted April 5, 2008 Author Share Posted April 5, 2008 Thanks, but when I do order by Price, it does not actually order them but sorts them out into the prices e.g. £12.99 £12.99 £10.99 £10.99 £15.99 £15.99, they are not in order from low to high. How would I make it order to low to high? Note, the numbers do not include the £ sign, e.g. 12.99. Link to comment Share on other sites More sharing options...
Synook Posted April 5, 2008 Share Posted April 5, 2008 What is the data type of your Price field? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.