Building a query string
Posted: Wed Nov 10, 2004 4:58 am
Hi all,
I have a page that lists many records from a db.
Now I wish the user to be able to sort the list by the titles on the columns which I have done by passing an $orderby via <a href> as below:
Further to this I only show 15 records per page so a pageid is also passed via the url.
Now both of these work just fine independently from one another. But now I have come to a bit of a head scratcher.
How do I build the url to either one of the above so that it takes into account any other actions the user may have performed on the page such as sort by title then clicks to view page 2, or is viewing page 2 then clicks to sort by date.
I hope I make sense.
I looked through the manual and I found $_SERVER["QUERY_STRING"]; which brings back any query after the foo.php but I am not sure how I should or can utilise this to help.
Could someone enlighten me please.
I have a page that lists many records from a db.
Now I wish the user to be able to sort the list by the titles on the columns which I have done by passing an $orderby via <a href> as below:
Code: Select all
echo "<td height="15"><a href="".$_SERVERї'PHP_SELF']."?orderby=title">Title</a></td>";
echo "<td><a href="".$_SERVERї'PHP_SELF']."?orderby=creation_date">Creation date</a></td>";
echo "<td><a href="".$_SERVERї'PHP_SELF']."?orderby=counter">Views</a></td>";
echo "<td><a href="".$_SERVERї'PHP_SELF']."?orderby=product">Product</a></td>";Code: Select all
//this is not all the code just a snippet to show how I build the url string.
for ($i = 0; $i < $pages; $i++) {
$url = "index.php?pageid=" . $i;How do I build the url to either one of the above so that it takes into account any other actions the user may have performed on the page such as sort by title then clicks to view page 2, or is viewing page 2 then clicks to sort by date.
I hope I make sense.
I looked through the manual and I found $_SERVER["QUERY_STRING"]; which brings back any query after the foo.php but I am not sure how I should or can utilise this to help.
Could someone enlighten me please.