• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

php and csv help


#1
Hi

I am designing a property website and have put some properties in a excel spreadhseet and saved it as a csv file and have used php coding to retrieve the data and display it on my webpage but how do I format the page so it is displayed in a nice table with borders

The coding is below

Code:
<?php

echo "<html><body><table>\n\n";

$f = fopen("properties.csv", "r");

while (($line = fgetcsv($f)) !== false) {

        echo "<tr>";

        foreach ($line as $cell) {

                echo "<td>" . htmlspecialchars($cell) . "</td>";

        }

        echo "<tr>\n";

}

fclose($f);

echo "\n</table></body></html>";
 

Levi

Moderator
Staff member
#3
Sunburn ..... CSV

I can download contact details, bank statements etc in this format. Basically it's a spreadsheet using comma's to donate colums, rows etc
 

Sunburn

Active Member
#4
@ Levi - Yes I know, but whats that got to do with the question .....

ianhaney28 said:
... used php coding to retrieve the data and display it on my webpage but how do I format the page so it is displayed in a nice table with borders


????
 

Redcentaur

Junior Member
#6
Why not have your php code separated from the html? That way you can easily include your css file. So...:

<html>
<head>
...
<link href="path/to/your/css.file">
</head>
<body>
<table>
<thead>...</thead>
<tbody>

<?php
$f = fopen("properties.csv", "r"); while (($line = fgetcsv($f)) !== false) { echo "<tr>"; foreach ($line as $cell) { echo "<td>" . htmlspecialchars($cell) . "</td>"; } echo "<tr>\n"; } fclose($f);

?>

</table>
</body>
</html>

Then, in your CSS file, all you need to do is reference the table and stick in the design elements you want. If you're unsure about the CSS, that's the easy part - give me a shout if you're unsure about CSS and I'll give you a head start. G