This is a discussion on "Displaying CSV file in PHP" within the PHP Forum section. This forum, and the thread "Displaying CSV file in PHP are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Displaying CSV file in PHP
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Displaying CSV file in PHP
I'm looking to display the contents of a CSV file on my PHP page.
You can view what I've done so far at: http://www.readingspeedway.co.uk/table06.php I'm fairly happy with that, but would now like to do the follow: 1. What I would also like to do is to have a second page which only displays certain columns (a smaller version of the table). The columns I wish to have displayed on that page is: M, PTS, BP, TOT 2. Also if possible 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 it will be highlighted in yellow text. What code do I need to add/ edit, to be able to do this? Please find below a print out of the current code on that page: <?php // $filename = "http://www.readingspeedway.co.uk/files/tables/spreadsheets/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; ?> |
|
|
|
#2
|
|||
|
|||
|
Re: Displaying CSV file in PHP
You can do what you want using css. Give each of the columns you don't want to appear on a certain page a class of say hide. Only have that class available on that page and use 'display: none;' to hid them. Similarly, give Reading and id and define a css style to suit your needs. |
|
#3
|
|||
|
|||
|
Re: Displaying CSV file in PHP
Quote:
Can you please take a look at my code I've pasted above and tell me how I can assign the READING class to the appropriate row. Please bear in mind Reading's position in the table may and will change. I have now managed to work out how to hide the appropriate columns thanks to your help. Thanks very much. Last edited by AndyP; Aug 15th, 2006 at 19:38. |
|
#4
|
|||
|
|||
|
Re: Displaying CSV file in PHP
In the code that reads your csv file, each time you read a name in, check to see if itis Reading and if it is, assign that cell the 'id' for the Reading style. |
|
#5
|
|||
|
|||
|
Re: Displaying CSV file in PHP
Quote:
I really need some help with this. Would I add something like this? $frmt_TeamName = 'style="color:#FFFF00; font-size:11px; " '; //make text yellow //say you want to READING row yellow text.... if($row == "Reading"){ $returnStr .= $frmt_TeamName; } |
![]() |
| Tags |
| displaying, csv, file, php |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how do I use a:hover within a html file (without the css file) | heyo | Web Page Design | 2 | Mar 5th, 2007 22:50 |
| Creating a log file (text file) and an XML file using XSL | kdelacruz | Other Programming Languages | 1 | Nov 4th, 2006 21:12 |
| PHP file displaying wrongly ??? | j4mes_bond25 | PHP Forum | 6 | May 19th, 2006 17:35 |
| Need help displaying XML | Zhan | Web Page Design | 5 | Aug 19th, 2005 18:47 |
| How make Word file same as html file in ASP | humair | Classic ASP | 5 | Sep 24th, 2003 14:35 |