Jump to content


Photo

Sorting Search Result with $_GET


  • Please log in to reply
4 replies to this topic

#1 barkster

barkster
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 19 August 2006 - 05:00 PM

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

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 19 August 2006 - 05:16 PM

Are you grabbing the data from a MySQL table???

If so

SELECT * FROM table WHERE field LIKE '%".$keyword."%' ORDER BY ".$Sorting." ".$Order."

So it looks something like
SELECT * FROM table WHERE fieldname LIKE '%test%' ORDER BY Price DESC

Just please remember to do some checks before using the GET vars, or you will be open to SQL INjection
Tell me the problem, I will try tell you the solution

#3 barkster

barkster
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 19 August 2006 - 05:36 PM

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

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 19 August 2006 - 06:16 PM

<a href='".$_SERVER['PHP_SELF']."?Keyword=".$_GET["Keyword"]."Description='".$_GET["Description"]."Sorting=Something&Order=Desc'>

Tell me the problem, I will try tell you the solution

#5 barkster

barkster
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 19 August 2006 - 06:28 PM

See knew it was simple I was trying to make it too hard. I'll try that thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users