Version: 1.0
Type: Function
Category: File Management
License: Other
Description: This function allows you to make a HTML table from *.csv (Excel without “”) divided into several pages, and you can change number of lines of the table with variable $numberrows. This table can be also a part of another page, and then you must use variable $calledfile (name of the “main page”), if you wanted to call the table itself then $calledfile = $targetfile.
variable $soubor is the source file.
I use also $tournament according to which I look for the name of the file with the table in data base and then include it into the main file..
I hope this is all.
I’m sorry for my English.
<?PHP function csv2table($soubor,$targetfile,$calledfile,$tournament,$numberrows,$tdclass,$tableclass,$pclass,$tablewidth) { $overall=0; $cislostr=0; $pocitadlo=0; $podminkabeg="n<?PHPrnif ($pozice=="; $podminkaend=") {rn "."?".">rn"; $headtable="<table width='".$tablewidth."' class='".$tableclass."'><tr>rn"; $endtable="</table>rn"; $formbackbeg="n<table width=".$tablewidth."><tr><form method='GET' action='".$calledfile."'>rn<td width='50%'><input type='hidden' name='turn' value='".$tournament."'><input type='hidden' name='pozice' value='"; $formbackend="'><input type='submit' name='back' value='zpet'></form></td>rn"; $formnotback="n<table width=".$tablewidth."><tr><td width='50%' align='left'></td>n"; $formforwbeg="<td width='50%' align='right'><form method='GET' action='".$calledfile."'>n<input type='hidden' name='turn' value='".$tournament."'><input type='hidden' name='pozice' value='"; $formforwend="'><input type='submit' name='forw' value='dopredu'></form></td>n</tr></table>"; $formnotforw="n<td width='50%'></td>n</tr></form></table>n"; $endofif="n<?PHPnr }n "."?".">n"; $attempt1="n<?PHPnrif ($pozice<0 or $pozice>"; $attempt2=") {nrecho('Bohuel, chyba v prov skriptu'); }"."?".">n"; //jadro funkce if (!file_exists($soubor)) { echo "chyba neexistence souboru ".$soubor; return FALSE; } if (!$fileread=fopen($soubor,"r")) { echo "chyba neotevreni souboru ".$soubor; return FALSE; } if (!$filewritten=fopen($targetfile,"w")) { echo "chyba neotevreni souboru k zapisu -".$soubor; return FALSE; } while (!feof($fileread)) { $overall++; $forward=$cislostr+1; $back=$cislostr-1; $pocitadlo++; if ($pocitadlo==1) { fwrite($filewritten,$podminkabeg.$cislostr.$podminkaend.$headtable); } fwrite($filewritten,"<tr>n"); $line=fgets($fileread, filesize($soubor)); $word=strtok($line,";"); while ($word) { fwrite($filewritten,"<td class='".$tdclass."'>".$word."</td>n"); $word=strtok(";"); } fwrite($filewritten,"</tr>n"); if ($pocitadlo==$numberrows) { if ($cislostr==0) { fwrite($filewritten,$endtable.$formnotback.$formforwbeg.$forward.$formforwend); fwrite($filewritten,$endofif); $pocitadlo=0; } else { fwrite($filewritten,$endtable.$formbackbeg.$back.$formbackend.$formforwbeg.$forward.$formforwend); fwrite($filewritten,$endofif); $pocitadlo=0; } $cislostr++; } } if ($cislostr==0) { fwrite($filewritten,$endtable); fwrite($filewritten,$endofif); fwrite($filewritten,$attempt1.$cislostr.$attempt2); fclose($filewritten); fclose($fileread); echo $overall; return $overall; } fwrite($filewritten,$endtable.$formbackbeg.$back.$formbackend.$formnotforw); fwrite($filewritten,$endofif); fwrite($filewritten,$attempt1.$cislostr.$attempt2); fclose($filewritten); fclose($fileread); echo $overall; return $overall; } ?>