php and csv help

Discussion in 'Programming' started by ianhaney28, Apr 18, 2012.

to remove all ads.
  1. ianhaney28

    ianhaney28 New Member


    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

    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";
    echo "\n</table></body></html>";
  2. goldenwaters

    goldenwaters Member

    Your php code on opening (csv) file is correct but i couldn't figure out the table placement.
  3. DesignerBill

    DesignerBill New Member

    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:

    This page will give you some help with CSS for formatting tables:

    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.

Share This Page