roldahayes Posted October 31, 2007 Share Posted October 31, 2007 hi Im using fgetcsv to output the reults of a csv file to a webpage. the test page is here http://www.rhinoracks.co.uk/test.php What im stuck on is formating the table to have different shading for odd and even rows... Any idea?? <? //Define what you want the seperator to be, this could be new line, (\n) a tab (\t) or any other char, for obvious reasons avoid using chars that will be present in the string. Id suggest a comma, or semicolon. $sep = ","; //define file to read $file = "./csv/berlingo.csv"; //read the file into an array $lines = file($file); //count the array $numlines = count($lines); //explode the first (0) line which will be the header line $headers = explode($sep, $lines[0]); //count the number of headers $numheaders = count($headers); $i = 0; //start formatting output echo "<table border = 1 cellpadding = 2><tr>"; //loop through the headers outputting them into their own <TD> cells while($i<$numheaders){ $headers = str_replace("\"", "", $headers); echo "<td>".$headers[$i]."</td>"; $i++; } echo "</tr>"; $y = 1; //Output the data, looping through the number of lines of data and also looping through the number of cells in each line, as this is a dynamic number the header length has to be reread. while($y<$numlines){ $x=0; echo "<TR>"; while($x<$numheaders){ $fields = explode($sep, $lines[$y]); $fields = str_replace("\"", "", $fields); echo "<TD> ".$fields[$x]." </TD>"; $x++; } $y++; echo "</TR>"; } //close the table. echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/75519-styling-of-fgetcsv-rusults-page/ Share on other sites More sharing options...
ToonMariner Posted October 31, 2007 Share Posted October 31, 2007 looks like more of a candidate for xml + xslt... without the FULL html you can't guarantee styling will be anything like consistent enough. Link to comment https://forums.phpfreaks.com/topic/75519-styling-of-fgetcsv-rusults-page/#findComment-382043 Share on other sites More sharing options...
roldahayes Posted October 31, 2007 Author Share Posted October 31, 2007 ok, so how would i best go about achieving this...? Link to comment https://forums.phpfreaks.com/topic/75519-styling-of-fgetcsv-rusults-page/#findComment-382049 Share on other sites More sharing options...
ToonMariner Posted October 31, 2007 Share Posted October 31, 2007 xml xslt Link to comment https://forums.phpfreaks.com/topic/75519-styling-of-fgetcsv-rusults-page/#findComment-382057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.