views:

83

answers:

2

I appreciate any help I can get with this problem:

  1. I have 2 search forms, one does a keyword search and the other does a search by country, state and city (with an input for each)
  2. The results are output to a table. The header row contains a link for sorting each column.
  3. Problem is I don't know how to build my GET url string for sorting and assign them to the links in the headers

Here is some code to get started (I am using MVC)

Functions

function searchkeyword()
{
    /* get keyword an query and output paginated result */
}

function searchcategory()
{
    /* get categories and query and output paginated result */
}

function sort()
{
    $sortby = $_GET['sortby'];
}

function paginate()
{
}

View

<th>
    <a href="sort.php?XXXX">Sort Column</a>
</th>

I'm not sure what should go in XXXX to sort the results.

A: 

Do you have to use the server to perform the sort? You could do it in Javascript on the client.

For an example, see any Wikipedia article which allows table sorting, such as this.

wallyk
yes that is true but I want to try it the non-JS way...in the office they are strict with the concept or progressive enhancements:)
Ygam
+1  A: 

if you want it to fit in $sortby = $_GET['sortby']; then you will need to use:

sort.php?sortby=param

where param is any of the possible sortby fields.

make sure that before putting this an any sql order by you check it yourself, so you don't get errors or attacks. ie:

switch $sortby:
    case 'city':
        $sort_string = 'ORDER BY `city`;
    ...
Brandon H