You are here: Re: seeking suggestion for posting spreadsheet data on web « HTML « IT news, forums, messages
Re: seeking suggestion for posting spreadsheet data on web

Posted by Toby Inkster on 08/24/05 10:28

Ross wrote:

> How to disable sorting by, say, length and chart ? I find the order is
> important to display so cannot just single them out from "array".

Slight improvement to my original function. Adds the ability to suppress
sorting for certain columns.

<?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) {
if ($options["nosort:$i"]==1) {
print "<th scope=\"col\">$h</th>";
} else {
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";

}

$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, 'nosort:2'=>1, 'nosort:6'=>1);
$c = 'My Caption';

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

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 

Navigation:

[Reply to this 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

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