1

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.

1
  • 1
    @Ygam: what did you tried so far, look to me to a give me the code question ... Commented Nov 20, 2009 at 5:13

2 Answers 2

1

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`;
    ...
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

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:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.