Reply to Problem of sorting table

Your name:

Reply:


Posted by Ross on 08/23/05 14:23

The following codes originally provided by a kind responder Toby A Inkster
in another newsgroup for working on displaying a table on web capable of
sorting are modified by me (a newbie). How to disable sorting by say, length
and chart (last few codes at the end)? I find the order is important to
display so cannot just single them out.

<?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";

}
?>

DATA,

<?php
$d = "A|3|5|1|10|3|<img src=\"fig/fig1.jpg\" width=120 height=90\>
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);
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация