Location: PHPKode > scripts > csv2table > csv2table/csv2table.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
        <title>CSV2table Manual</title>
</head>

<body>

<h2>CSV2Table</h2>
&copy; 2001, by Sivaprasad R.L &lt;hide@address.com&gt;,<br>
http://netlogger.net
<br>
<br>
An easy to use PHP class to display a CSV (Comma Separated Values) file in<br>
the form of an HTML table.
<br><br>
<hr>
<h3>Methods:</h3>
<h4><li>set_header(val)</li></h4>
Valid parameter values : <b>"OFF"</b> / <b>"ON"</b>
<br><br>
Use this function to customize the appearence of the top row.
To remove header highlighting and to display the top row exactly same
as the others call: set_header("OFF").The default value is set to "ON".

<h4><li>set_headercolor($col1,$col2) </li></h4>
Function to set the foreground and background color of the topmost row.
For eg : to set the topmost row in black background with text in white :
<pre>    set_titlecolor("#000000","$ffffff");</pre>

<h4><li>set_bgcolor($col1,$col2) </li></h4>
Function to set the background color of alternating rows. Both colors
will be used as background colors alternatively. <br>
For eg : to display red and blue as alternating background colors for the rows in the table:
<pre>    set_bgcolor("#ff0000","$0000ff");</pre>


<h4><li>set_fontcolor($col1,$col2) </li></h4>
Function to set the font colors of the text in alternating rows.
For eg : to display black and white as alternating font colors for the rows in the table:
<pre>    set_fontcolor("#000000","$ffffff");</pre>

<h4><li>set_tablewidth($width) </li></h4>
Function to set the table width in percentile.
For eg : to display a table with width= 50%:
<pre>    set_tablewidth("50%");</pre>

<h4><li>showtable(csvfilename,tabletitle,columnstoshow="",filter="")</li></h4>
This is the main method used to display a csvfile as an HTML table. The last two
parameters 'columnstoshow' and 'filter' are <b>optional</b>. By default, when last
two parameters are omitted, all columns and rows in the csv file are displayed.

<br><br>
<b>Parameters:</b>
<hr size=1 width=11% align=left>
<b>'csvfilename' -</b> The name of the csvfile with the extension .csv.
<br><br>
<b>'tabletitle' -</b> A string to display the title.
<br><br>
<b>'columnstoshow' -</b> A string which contains the list of column numbers (separated by ',')
in the csv file that are to be displayed. By default, all fields in the csv file are shown.
This optional parameter is passed only to display chosen columns from a csv file,
<br><br>
<b>'filter' -</b> An array of filters (conditions to check) to apply before displaying a row.
This optional parameter is defined as follows..
<br>
<center><b>$filter[fieldnum] = "&lt;operator&gt;,&lt;value&gt;";</b></center>
The 'fieldnum' is the column number in csvfile. An operator is the operation applied to the data and
value. It can take any of the following logical comparison operators '&lt;' , '&gt;' , '!=' , '=' </b>.
The 'value' specfied here next to the operator will be compared to the actual data from the corresponding
column (specified using fieldnum) in csv file. If the filter validates to true, the row is displayed, or
otherwise the current row will be skipped and will move on to the next row.
<br><br>
For example: If we want to display a row, only when the value of 'age' exceeds 25
and if the 'age' column number in csv file is '1', then the filter should be..
<br>
<pre>

         Operator       Value
               \        /
                \      /

    $filter[1] = "&gt;, 25";
            |
            |
            o----> Column number in CSV file
</pre>
<hr size=1>
<h4>Example 1:</h4> To display the csv file
<pre>
&lt;?
    include "csv2table.inc";
    $csv = new csv2table();
    $csv->showtable("customer.csv","Customer Details");
?&gt;
</pre>


<h4>Example 2:</h4>
To display 1st and 3rd column of the csv file with two filters.
<pre>
&lt;?
    include "csv2table.inc";

    // if req, you can pass the path where all your csv files are located as a parameter
    // in the constructor. (note: there is a trailing slash after the directory name)

    $csv = new csv2table("csv/");

    $filter[1] = ">,20";
    $filter[3] = "!=,joe";

    $csv->set_header("OFF");
    $csv->set_tablewidth("50%");
    $csv->showtable("customer.csv","Customer Details","1,3",$filter);
?&gt;
</pre>

</body>
</html>
Return current item: csv2table