Member Offer
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

php and csv help

Discussion in 'Introduction Forum:' started by ianhaney28, Apr 18, 2012.

  1. ianhaney28

    ianhaney28 Junior 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>";
     
  2. Sunburn

    Sunburn Active Member

  3. Levi

    Levi Moderator Staff Member

    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
     
  4. Sunburn

    Sunburn Active Member

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



    ????
     
  5. Levi

    Levi Moderator Staff Member

    my fault, misread it
     
  6. Redcentaur

    Redcentaur Junior Member

    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
     

Share This Page