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.
|
|
|
|
|
![]() |
||
Sorting A Table By Column Header
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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 |
|
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
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 |
![]() |
| Tags |
| sort table |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding a column to a table | Jack Franklin | Databases | 2 | Feb 3rd, 2008 08:17 |
| How to automatically 'add column' to table? | skuliaxe | Databases | 1 | Jan 22nd, 2008 10: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 |