barkster Posted August 19, 2006 Share Posted August 19, 2006 I'm trying to implement a sorting on my recordset using $_GET variables. What is the best way to implement this? I want to have a link on a page for ordering by price and date but do I have to capture the url string and replace the order variable somehow to create the link with the correct sorting. I want them to be able to sort back and forth between price and date but I can't figure out how to change the url parameters on the page. for instance SearchResults.php?Keyword="Test"&Description=""&Sorting="Price"&Order="Desc"Thanks Link to comment https://forums.phpfreaks.com/topic/18040-sorting-search-result-with-_get/ Share on other sites More sharing options...
onlyican Posted August 19, 2006 Share Posted August 19, 2006 Are you grabbing the data from a MySQL table???If soSELECT * FROM table WHERE field LIKE '%".$keyword."%' ORDER BY ".$Sorting." ".$Order."So it looks something likeSELECT * FROM table WHERE fieldname LIKE '%test%' ORDER BY Price DESCJust please remember to do some checks before using the GET vars, or you will be open to SQL INjection Link to comment https://forums.phpfreaks.com/topic/18040-sorting-search-result-with-_get/#findComment-77288 Share on other sites More sharing options...
barkster Posted August 19, 2006 Author Share Posted August 19, 2006 Yeah know how to do that part and I probably was't that clear. My problem is creating the link for instance if someone does a search and I'm doing $_Get to get the search keywords etc... then I have to incorporate that back into the link on the page for the sorting. For instance if searchresults.php?keyword=test&description="" then I need to create a link on the page to searchresults.php?keyword=test&description=""&sorting=price&order=asc but then I want to have them be able to sort by date also so then I would have to get the url and change the sorting to sorting=date I guess I'm answering my own question but I didn't know if I had to get the url string and strip the sorting=date out and replace with sorting=price or if there was an easier way of building those dyamic links somehow Link to comment https://forums.phpfreaks.com/topic/18040-sorting-search-result-with-_get/#findComment-77297 Share on other sites More sharing options...
onlyican Posted August 19, 2006 Share Posted August 19, 2006 <a href='".$_SERVER['PHP_SELF']."?Keyword=".$_GET["Keyword"]."Description='".$_GET["Description"]."Sorting=Something&Order=Desc'> Link to comment https://forums.phpfreaks.com/topic/18040-sorting-search-result-with-_get/#findComment-77301 Share on other sites More sharing options...
barkster Posted August 19, 2006 Author Share Posted August 19, 2006 See knew it was simple I was trying to make it too hard. I'll try that thanks Link to comment https://forums.phpfreaks.com/topic/18040-sorting-search-result-with-_get/#findComment-77304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.