Free Web Hosting Forum
(#1 (permalink))
Old
Junior Member
kev7607 is on a distinguished road
 
Posts: 2
Join Date: Nov 2011
Default newbie question on sorting tables - 11-07-2011, 11:25 PM

Hi,
Probably a simple question for you experts.
On my website I have a table of players with their teams, values, points etc.
Id like to make it so that the list can be sorted by value or alphabetically.
Can somebody give me some help or point me in the right direction.
Many Thanks
Kev
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
ShocK's Avatar
Senior Member
ShocK is on a distinguished road
 
Posts: 1,622
Join Date: Jul 2011
Location: UK
Default 11-08-2011, 07:54 AM

Hi, I take it you mean auto sorted and not manual? If so then I reckon you'll need a database and a script and then someone much better qualified than me to follow up.
Reply With Quote
(#3 (permalink))
Old
bubt's Avatar
Member
bubt is on a distinguished road
 
Posts: 47
Join Date: Sep 2009
Default 11-08-2011, 06:52 PM

Basically there two ways to accomplish what you want.

1. If you don't want to use a database I would recommend using javascript to sort and order your table.
People who don't have javascript unabled will just see your table everyone else will be able to sort and order the table.

Example see this website:
http://yoast.com/articles/sortable-table/

2. More advanced would be to store your player information into a database
and use php queries to return your table and order it.
Which would require you to use $_GET variables to order and sort your query.

Here is a small Example:
Code:
// database connection script

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

// if the url looks like this page.php?order=teams
// php will order by teams
if (isset($order) && (!empty($order)) )
{
      $extend_query = 'ORDER BY ' . $order;
}

// get your players data from db
$sql = 'SELECT * FROM table ' . $extend_query;
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)
{
    // echo table
}
Basically the idea behind it is to extend and change your database query to change the output to the page.

Last edited by bubt; 11-08-2011 at 07:00 PM.
Reply With Quote
(#4 (permalink))
Old
Junior Member
kev7607 is on a distinguished road
 
Posts: 2
Join Date: Nov 2011
Default 11-08-2011, 07:26 PM

Quote:
Originally Posted by bubt View Post
Basically there two ways to accomplish what you want.

1. If you don't want to use a database I would recommend using javascript to sort and order your table.
People who don't have javascript unabled will just see your table everyone else will be able to sort and order the table.

Example see this website:
http://yoast.com/articles/sortable-table/

2. More advanced would be to store your player information into a database
and use php queries to return your table and order it.
Which would require you to use $_GET variables to order and sort your query.

Here is a small Example:
Code:
// database connection script

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

// if the url looks like this page.php?order=teams
// php will order by teams
if (isset($order) && (!empty($order)) )
{
      $extend_query = 'ORDER BY ' . $order;
}

// get your players data from db
$sql = 'SELECT * FROM table ' . $extend_query;
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)
{
    // echo table
}
Basically the idea behind it is to extend and change your database query to change the output to the page.
Thanks bubt, just what I was looking for - Kev
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com