开发者

Link structure for sorting an HTML table built using PHP

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"&开发者_如何学编程gt;Sort Column</a>
</th>

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


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`;
    ...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜