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


&copy; 2001, by Sivaprasad R.L &lt;hide@address.com&gt;,<br>
An easy to use PHP class to display a CSV (Comma Separated Values) file in<br>
the form of an HTML table.
Valid parameter values : <b>"OFF"</b> / <b>"ON"</b>
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>

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.

<hr size=1 width=11% align=left>
<b>'csvfilename' -</b> The name of the csvfile with the extension .csv.
<b>'tabletitle' -</b> A string to display the title.
<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,
<b>'filter' -</b> An array of filters (conditions to check) to apply before displaying a row.
This optional parameter is defined as follows..
<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.
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..

         Operator       Value
               \        /
                \      /

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

<h4>Example 2:</h4>
To display 1st and 3rd column of the csv file with two filters.
    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->showtable("customer.csv","Customer Details","1,3",$filter);

Return current item: csv2table