Jump to content

How to add a sort by button...


Alexhoward

Recommended Posts

Hi Everyone!

 

I'm just looking for some advice before i start messing around with any code

 

What i'd like is some sort by buttons

 

e.g. - Name - Rating...etc

 

But i'm not sure how to do this...

 

what i'd really like it to do is something like:

 

in the code:

 

select * from 'where_ever' sort by $button

 

then some kind of way to say that when a button is pressed it sets the variable

 

Is that possible?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/
Share on other sites

well you mean like button or link?

 

if you make a link you can make it something like this

<?php

$sortby=$_GET['sortby'];
$sort=$_GET['sort'];

if (!$sortby) { $sortby="name"; }
if (!$sort) { $sort="desc"; }

if ($sort=="asc") { $ascdesc = "desc"; }
elseif ($sort=="desc") { $ascdesc = "asc"; }

echo '<a href="filename.php?sortby=name&sort='.$ascdesc.'"><br />";

$result=mysql_query("SELECT * FROM `table` SORT BY $sortby $sort");
// ... Follow up with the rest of the code here ...
?>

 

hope this guides u a little further :)

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.