How to sort search results in PHP or JS

Discussion in 'Programming' started by hm99, Oct 7, 2010.

  1. #1
    Hi,

    I want to sort the database search results in php or somethingelse. Basically, the results are returned on a php page and need to be sorted either by columns. I managed to display the results on the page with the code below and it works, but now i need to add the sorting bit, but i am stuck with it. I dont want to fetch the data from the database again but just to manipulate the existing entries. how can this be achieved in php?


    $sql .= 'SELECT    * FROM dealstable  WHERE  search  like "%' . $dest . '%" ';
    
    
    $result = mysql_query($sql) or die("Query error: ".mysql_errno().": ".mysql_error());
    
    
    while ($row = mysql_fetch_array($result))
    {
    
    print "<tr>"
    ;
    
    
    print "<td><img  height='60' src='" . $row["id"] . "'></td>"
    ;
    
    print "<td align='center'>" . $row["deals"] . "</td>"
    ;
    Code (markup):
    want to add the sort option on the search results so that users can filter

    something like:

    Sort  by 
    <select name="sort" " id="sort" style="width:150px;">
    <option value="lowprice">Lowest Price Asc</option>
    <option value="highprice">Highest Price Desc</option>
    etc
    Code (markup):

    Thanks in advance
     
    hm99, Oct 7, 2010 IP