Jump to content

Sorting data without using Tables.


svdb

Recommended Posts

I've got a database that I display in php with:$q = "SELECT * FROM entries ORDER BY votes_up DESC";That's no problem. But the data is displayed in divs and in such a way tables won't be able to give the same result. All tutorials I find are based on tables so I can't figure out what to do in my case.Besides votes_up I've got two more columns I want to sort the data by. This should be done by clicking on a button. One for each.So what I thought was to replace votes_up by variable $order. $q = "SELECT * FROM entries ORDER BY $order DESC";What I need now is a way to change this variable on client side by clicking one of those three buttons and so that the page refreshes and displays the data in the chosen order.Hope I made my self clear and someone can help.Thanks

Link to comment
Share on other sites

You can just send a $_POST or $_GET variable. Put your three buttons in a form with an empty action attribute. Don't omit the action just leave it empty (action="") that way the form will submit to the current page. You may need some javascript to do a $_POST but you could use plain HTML links if you use $_GET instead.Then in your PHP just test the $_POST or $_GET variable to determine which field to sort by.Here's some links, just in case:$_GET$_POST

Link to comment
Share on other sites

Thanks, I got this workingBut now their is this other problem. I've my data on different pages that work wit GET as well. So as soon as you go to the next page it sorts as default.Is their an simple solution or does it depend on your script etc. thanks again.

Link to comment
Share on other sites

Yes you're right.The data comes from one table and displaying it is limited by 10 items a page. So if I sort it by date it has to be sorted on all the pages by date.Going to page two makes it know sorting it again by default..

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...