Forum Moderators: coopster
I'm fairly happy with that, but would now like to do the follow:
1. I would like 'READING'S' row to be displayed in a different colour. So for example if Reading are currently top of the league, or mid table, then that row will be highlighted in yellow text.
2. I'd also like to get the date on a separate line so I can add some text, e.g."Table correct up to and including <DATE INSERTED HERE>"
What code do I need to add/ edit (see code below), to be able to do this?
Please find below a print out of the current code on that page:
<?php
//
$filename = "http://www.somesite.com/table06.csv"; // File to open. quote out this variable if you are using a form to link to this script.
/*
No cache!
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
/*
End of No cache
*/
function viewlog($filename) {
//formatting options...
$alignCentre = 'align="center" ';
$frmt_embolden = 'style="font-weight:bold; font-size:11px" ';
//start the table...
$returnStr = "<table border=0 bordercolor=white cellspacing=1 cellpadding=1 width=95% font-family: Verdana, Arial, Helvetica, sans-serif; align='center' style='font-size:11pt'>";
$handle = fopen($filename,"r");
while (($data = fgetcsv($handle, 1000, ","))!== FALSE) {
$num = count($data); // <--- this is the number of columns in the line read in....
$row++;
//each line represents a row, so open the row...
$returnStr .= "<tr>";
for ($i=0; $i < $num; $i++) {
//now insert the column details...
//say you want to align cols centre then
if($i == 0 ¦¦ $i == 2 ¦¦ $i == 3 ¦¦ $i == 4 ¦¦ $i == 5 ¦¦ $i == 6 ¦¦ $i == 7 ¦¦ $i == 8 ¦¦ $i == 9 ¦¦ $i == 10 ¦¦ $i == 11 ¦¦ $i == 12 ¦¦ $i == 13){
$returnStr .= "<td " . $alignCentre;
}else{
$returnStr .= "<td ";
}//end if-else
//say you want to embolden the heading row...
if($row == 3){
$returnStr .= $frmt_embolden;
}
$returnStr .= "> " . $data[$i] . "</td>";
}//end for
//close the row...
$returnStr .= "</tr>";
}//end while
//end the table...
$returnStr .= "</table>";
//gets the last mod date of the file...
$fileModTime = filemtime($filename);
//now format the date...
$fileModTime = date("D d M Y", $fileModTime);
fclose($handle);
return $returnStr;
}//end function
echo "<html><head><base href=\"./\"><title>ELITE LEAGUE TABLE - TEST</title>
<style type='text/css'>
<!--
body,td,th {
font-family: arial, verdana, tahoma, sans-serif;
font-size: 11px;
color: #FFFFFF;
}
-->
</style>
</head><body bgcolor=#b2181a>";
// Start the table definition of your choice
echo "<p>";
echo viewlog($filename);
echo "</p></body></html>";
exit;
?>
[edited by: dreamcatcher at 1:08 pm (utc) on Aug. 17, 2006]
[edit reason]
[1][edit reason] No urls as per TOS [webmasterworld.com] Thanks. [/edit] [/edit][/1]
To get different colors in a table row you just need to watch for the change in value as you read from your file and modify the <tr> element accordingly. Something along the lines of ...
while (looping through csv file) {
$class = '';
if ($myData == 'READINGS') {
$class = ' class="yellow"';
}
print "<tr$class><td>$myData</td></tr>";
}