Sorting A Table By Column Header

This is a discussion on "Sorting A Table By Column Header" within the Databases section. This forum, and the thread "Sorting A Table By Column Header are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Dec 4th, 2006, 11:44
Junior Member
Join Date: Aug 2006
Location: Leeds
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Sorting A Table By Column Header

Hi there,

I have a database which displays product information: Name, Description, Size, Unit Price & Image, and want to be able to sort each column by clicking on the appropriate column heading.
I would be grateful for any help on how to do this.

I am also wanting to be able to use the images as thumbnails so that when one is selected it opens in a new window. Does anyone have any help on this as well.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 4th, 2006, 23:29
Up'n'Coming Member
Join Date: Jun 2006
Location: Rochester, NY
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sorting A Table By Column Header

a great sample of this is in phpmyadmin.

Use
ORDER BY `table`.`col` ASC (or DESC)

LIMIT 0 , 30
might help you aswell, the first number is what row you want it to start at, the second is how many rows. this is helpfull if you want to have more then 1 page of table data.

so if you had abunch of time stamps on things that had been edited you could sort by time Ascending and make it eaiser to find what you want.
__________________
www.MonsterCoding.com - Website Programming and Development Services
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 5th, 2006, 17:34
Junior Member
Join Date: Aug 2006
Location: Leeds
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sorting A Table By Column Header

Thanks for the info.

I have managed to sort the columns by ascending through using:

$order = $_GET["order"];
if (!$order=="")
{
$query = $query." order by $order ";
}

if (mysql_num_rows($result) > 0) {
echo "<table cellpadding=10 border=1>";
echo "<tr><td><a href='products.php?order=Name&letter=$initialLette r'>Name</a></td>".

I used this as I could not find the information in phpMyAdmin.
Is there a way in which I can adapt this coding to make it do both ascending & descending?

Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 6th, 2006, 00:21
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sorting A Table By Column Header

You could put the resource into arrays, format it as a form, and use asort() or even ksort() on submit (hidden in the <th>). I always use numerical arrays anyway if possible, just because it's so much faster.

I'd whack it out for you except I'm a little shaky on my multidimensional array syntax and don't want to look like an even bigger idiot than usual. Curly brackets are so picky. But you could do pretty much anything you wanted once you laid the groundwork like that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Dec 8th, 2006, 02:53
Up'n'Coming Member
Join Date: Jun 2006
Location: Rochester, NY
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sorting A Table By Column Header

figureing out what youve actually done with your arrays is the hardest part...
i like when i can get sql to do things for me.

do both ascending and descending? you mean sort 1 column then if those are the same look to another? like a music library kinda.
uhh ill look into it for you because i would like to know aswell.

hmm, maybe thats not what your looking for because thats actually quite simple.
ORDER BY `user` , `mod` ASC would do that.


Ascending and Descending i just did it.
ORDER BY `user` ASC , `mod` DESC


hope that helps ya, kinda sloppy of me...
__________________
www.MonsterCoding.com - Website Programming and Development Services
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
sort table

Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a column to a table Jack Franklin Databases 2 Feb 3rd, 2008 09:17
How to automatically 'add column' to table? skuliaxe Databases 1 Jan 22nd, 2008 11:40
Sorting a PHP array fallen_angel PHP Forum 3 Apr 20th, 2007 22:18
..copy data from column A in Table A to column B in Table B? gecastill Databases 10 Jun 23rd, 2005 18:27
Table Column Headings and Page Breaks Trebz Web Page Design 8 Jun 4th, 2004 12:55


All times are GMT. The time now is 12:26.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved