Tables

Gat_Decor

Fledgling Freddie
Joined
Aug 7, 2004
Messages
394
Hi guys,

Quick bit of help if poss, I would like to be able to have a page pull data from a text/csv file and display it 'table' stylee, so all i need to do to update the page is, change the text/csv file and upload it....

I have have something that will do this now but IE moans about activeX scripts being run and FF wont display the info from the CSV at all.

I don't really want to go down the Mysql route and have data pulled from there, all the table will display is names and a few numbers in columns and rows.. with headers of course

ta
 

SheepCow

Bringer of Code
Joined
Dec 22, 2003
Messages
1,365
This bit of PHP should do it, it is however completely untested.

PHP:
<?php

$datafile = 'file.csv';
$delim = ',';

$fp = fopen($datafile, 'r');
$headers = true;

echo '<table>';

while (!feof($fp)) {
    $line = fgets($fp, 4096);
    $bits = explode($delim, $line);

    echo '<tr>';

    if($headers) {
        $headers = false;
        $html = 'th';
    } else {
        $html = 'td';
    }

    foreach ($bits as $bit) {
        echo "<$html>", trim($bit), "</$html>";
    }    

    echo '</tr>';
}

echo '</table>';

?>

Should if you didn't want a PHP script etc. :)
 

Users who are viewing this thread

Top Bottom