Sortable Table
Moderator: General Moderators
-
Nick Ewing
- Forum Newbie
- Posts: 3
- Joined: Sun Sep 14, 2003 4:02 pm
Sortable Table
Hello, I'm trying to make a table that that when you sort one colum it keeps the other colums in the right place. So it would be something like this:
before sorting:
a b c
3 1 2
1 2 3
2 3 1
after sorting the a colume:
a b c
1 2 3
2 3 1
3 1 2
before sorting:
a b c
3 1 2
1 2 3
2 3 1
after sorting the a colume:
a b c
1 2 3
2 3 1
3 1 2
There is no such thing (array_sort).
http://se.php.net/manual/en/function.ar ... tisort.php or http://se.php.net/manual/en/function.sort.php might be worth looking into.
But you do not mention how you are building this table, and by table do you meant a <table> as in html?
http://se.php.net/manual/en/function.ar ... tisort.php or http://se.php.net/manual/en/function.sort.php might be worth looking into.
But you do not mention how you are building this table, and by table do you meant a <table> as in html?
-
Nick Ewing
- Forum Newbie
- Posts: 3
- Joined: Sun Sep 14, 2003 4:02 pm
the table
well i want to accomplsh something like what apache does with directories
example:
http://nickewing.gotdns.com/pictures/
So when i click the Name colum it sorts the name colum and puts the other information in the right place
example:
http://nickewing.gotdns.com/pictures/
So when i click the Name colum it sorts the name colum and puts the other information in the right place
Found this on php.net, as sorting multidimensional arrays has not got a function (what I know of):
Hope you can make some use of this. Supports multible sorting also, by adding more fields as in the last example in the code.
Code: Select all
<?php
$array[1]['name'] = 'A';
$array[2]['name'] = 'B';
$array[3]['name'] = 'C';
$array[1]['size'] = 'C';
$array[2]['size'] = 'B';
$array[3]['size'] = 'A';
$array[1]['type'] = 'C';
$array[2]['type'] = 'A';
$array[3]['type'] = 'B';
// function found on php.net
function array_csort() { //coded by Ichier2003
$args = func_get_args();
$marray = array_shift($args);
$i = 0;
$msortline = "return(array_multisort(";
foreach ($args as $arg) {
$i++;
if (is_string($arg)) {
foreach ($marray as $row) {
$sortarr[$i][] = $row[$arg];
}
} else {
$sortarr[$i] = $arg;
}
$msortline .= "\$sortarr[".$i."],";
}
$msortline .= "\$marray));";
eval($msortline);
return $marray;
}
// lets test it
$test1 = array_csort($array,'size');
print_r($test1);
$test2 = array_csort($array,'type');
print_r($test2);
$test3 = array_csort($array,'name','type');
print_r($test3);
?>-
Nick Ewing
- Forum Newbie
- Posts: 3
- Joined: Sun Sep 14, 2003 4:02 pm
Re: the table
You mean a type of directory viewer? Maybe open_dir() was what he was looking for, guys. Search for open_dir() at php.net. It might be what you're looking for.Nick Ewing wrote:well i want to accomplsh something like what apache does with directories
example:
http://nickewing.gotdns.com/pictures/
So when i click the Name colum it sorts the name colum and puts the other information in the right place
Hope that helps...
-Nay
thanx jam. i was thinking array_multisort. it's meant to do multiple sorting types upon multiple types of arrays.JAM wrote:There is no such thing (array_sort).
http://se.php.net/manual/en/function.ar ... tisort.php or http://se.php.net/manual/en/function.sort.php might be worth looking into.
But you do not mention how you are building this table, and by table do you meant a <table> as in html?
have you thought of javascript? it might be faster to use javaascriptNick Ewing wrote:well i want to accomplsh something like what apache does with directories
example:
http://nickewing.gotdns.com/pictures/
So when i click the Name colum it sorts the name colum and puts the other information in the right place
- SantaGhost
- Forum Commoner
- Posts: 41
- Joined: Mon Sep 15, 2003 11:54 am