php and csv help

ianhaney28

New Member
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>";
 
Use CSS

You need to add some styling for your table with CSS. You will need to include a <head> section between your <html> and <body> tags. An external CSS file that you access with a <link> tag is the best way, but you could also use internal styles in your <head> between <style> and </style> tags.

See this page for a description of the external and internal style methods:
http://www.w3schools.com/css/css_howto.asp

This page will give you some help with CSS for formatting tables:
http://www.w3schools.com/css/css_table.asp

By the way you don't need to use "echo" statements in your script for all the output. You can just write the plain html and it will be sent to the browser as written. Use "echo" only for the html that you are dynamically creating in the script.
 
Top