svdb Posted April 21, 2010 Share Posted April 21, 2010 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 More sharing options...
ShadowMage Posted April 21, 2010 Share Posted April 21, 2010 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 More sharing options...
svdb Posted April 21, 2010 Author Share Posted April 21, 2010 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 More sharing options...
ShadowMage Posted April 21, 2010 Share Posted April 21, 2010 Not sure I quite understand the problem.You have several pages with similar data. If you sort one of them by say, a date, you want them all to sort by that date?Does that sound right or am I way off? Link to comment Share on other sites More sharing options...
svdb Posted April 22, 2010 Author Share Posted April 22, 2010 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 More sharing options...
ShadowMage Posted April 22, 2010 Share Posted April 22, 2010 OK, gotcha. You can probably still pass that same $_GET variable to the second page and have it sort on that somehow. I'm not familiar with pagination scripts so I'm not sure. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.