Ross wrote:

I am seeking your advice on the programming language for such an action. i prefer a web table capable of sorting by size, length and so on, therefore built-in function for sorting is appreciated.

Down below are a couple of nice PHP functions that may be of use. I've taken them from my CMS at work and munged them a little to make them independent of it. I've not tested these munged ones, so they may need a little adjusting.

Below the PHP code are some instructions on how they should be used.


<?php
function insert_datatable_cmp ($a, $b) {
    return ($a[$_GET['sort']]<$b[$_GET['sort']]) ? -1 : 1;
}
	
function insert_datatable ($data, $headings, $options=array(), $caption='')
{
    if ($caption!='' && $options['h2']==1) print "<h2>$caption</h2>\n";
    print "<table>\n";
    if ($caption!='' && $options['h2']!=1) print "<caption>$caption</caption>\n";
    print "<thead><tr>";
    $i = 0;
    foreach ($headings as $h)
    {
        print "<th scope=\"col\"><a href=\"${_SERVER['PHP_SELF']}?sort=$i\">$h</a></th>";
        $i++;
    }
    print "</tr></thead>\n<tbody>\n";
                
        $lines = explode("\n",$data);
        $i = 0;         
        while ($l = array_shift($lines))
            $s[$i++] = explode("|",$l);
                
    if(isset($_GET['sort']))
        usort($s,"insert_datatable_cmp");
                
    foreach ($s as $S)
    {
        print "<tr>";
        for($i=0;$S[$i];$i++)
        {
            if ($options['email:'.$i]==1) 
            {
                $S[$i] = '<a href="mailto:' . $S[$i] . '">' . $S[$i] . '</a>';
            }
            elseif ($options['web:'.$i]==1) 
            {
                $S[$i] = '<a href="' . $S[$i] . '">' . $S[$i] . '</a>';
            }

            if ($options['join:'.$i.':'.($i+1)]==1)
            {
                print '<td colspan="2">' . $S[$i] . ' ' . $S[$i+1] . '</td>';
                $i++;
            }
            else
            {
                print '<td>' . $S[$i] . '</td>';
            }
        }
        print "</tr>\n";
    }

    print "</tbody></table>\n";
}
1?>

To create the table you posted, you would do this:


<?php
$d = "A|3|5|1|10|3|figA.gif
B|5|2|2|4|3|figB.gif
C|4|3|3|9|6|figC.gif";

$h = array('name','size','length','0min','3min','10min','chart');
$o = array('web:6'=>1);
$c = 'My Caption';

insert_datatable($d, $h, $o, $c);
1?>

As you can see, the first argument for the insert_datatable() function is a pipe-seperated table of data. The second argument is a PHP array of headings. The third argument is an array of "options" (explained later). The last argument is a caption for the table. The first two arguments are required. The last two are optional. (But if you include a caption, you must also include the options array!)

The options are set like this:


<?php
$o = array('option1'=>1, 'option2'=>1, 'option3'=>1);
1?>

so that the "=>1" means "switch this option on".

What options can be used? "web:X" means that column number X is a web link. "email:X" means that column X is an e-mail address. "join:X:Y" means that columns X and Y should be joined (useful if X is a person's first name and Y is their surname!). Column numbers start from 0, not 1.

That's about it!