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
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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.