|
-
Dec 30th, 2006, 06:50 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Sorting by a column
I've seen loads of tables where I can click on the heading title and it will sort the table in order - does anyone know how this is done or any good tutorials on it?
-
Dec 30th, 2006, 06:59 PM
#2
Re: Sorting by a column
Usually the data displayed is from a database which is where the sorting takes place.
eg.
PHP Code:
//When page loads for first time show in ASC order
$sSQL = "SELECT * FROM YourTable ORDER BY YourField ASC"
//Then when column heading is clicked do the opposite sorting.
$sSQL = "SELECT * FROM YourTable ORDER BY YourField DESC"
-
Dec 30th, 2006, 07:00 PM
#3
Thread Starter
Hyperactive Member
Re: Sorting by a column
Thanks for that - I was wondering when the user clicks on the column does it call a function on another php page or a function within the same page??? How does it work - do you have any examples?
-
Dec 30th, 2006, 07:10 PM
#4
Re: Sorting by a column
This link should help you out
-
Dec 30th, 2006, 07:12 PM
#5
Thread Starter
Hyperactive Member
Re: Sorting by a column
Hmmm, nope there's an error - I get: 'Error: A problem was encountered while executing this query.'
Strange.... anyway I'll search on this topic for more info...
-
Dec 30th, 2006, 07:21 PM
#6
Re: Sorting by a column
Use the query string to specify the field to sort by and the direction.
Ensure that these values are properly sanitized in your code to ensure no other data except the column name appears in the query.
-
Dec 30th, 2006, 07:23 PM
#7
Thread Starter
Hyperactive Member
Re: Sorting by a column
Have you got any examples pleasE?????
-
Dec 30th, 2006, 07:40 PM
#8
Re: Sorting by a column
 Originally Posted by wwwfilmfilercom
Have you got any examples pleasE?????
Write it yourself and stop being lazy.
-
Dec 30th, 2006, 09:54 PM
#9
Re: Sorting by a column
 Originally Posted by wwwfilmfilercom
Have you got any examples pleasE?????
http://google.com/search?q=query+string+php
-
Dec 30th, 2006, 09:56 PM
#10
Re: Sorting by a column
The link that lintz provided gives enough information and example of the very thing you want, except you probably want to include the ability to either sort by ascending or descending, which is just another quick step. in the link he posted, you use $_GET['order'] for the column name you're sorting by and you could just add $_GET['sort'] or something that would contain either "ascending" or "descending" (or any shortened abbreviations, like asc/desc, a/d, etc), then you just tack the command (either ASC or DESC) onto the end of your query and you're ready to go.
it's quite simple, really.
-
Jan 2nd, 2007, 07:58 AM
#11
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|