#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Displaying CSV File in a Table Using PHP


    Hello Can anyone advise me on how I can display a CSV File in a Table Using PHP.

    I can display the data in a line using the following:-

    PHP Code:

    <html>
    <head>
    <title>A BASIC HTML FORM</title>
    <body>

    <?PHP
     
    $file_handle 
    fopen("csv/pins.csv""r");
     
    while (!
    feof($file_handle) ) {
     
    $line_of_text fgetcsv($file_handle1024);
     
    print 
    $line_of_text[0] . $line_of_text[1]. $line_of_text[2] . $line_of_text[3] . $line_of_text[4] ."<BR>";
     
    }
     
    fclose($file_handle);
     
    ?>
    </body>
    </html>
    I want to move text[0], text[1] etc into cells in a table

    Any assistance would be appreciated

    Thanks
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,866
    Rep Power
    6351
    PHP Code:
    print '<tr><td>' $line_of_text[0] . '</td><td>' $line_of_text[1]. //etc 
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by ManiacDan
    PHP Code:
    print '<tr><td>' $line_of_text[0] . '</td><td>' $line_of_text[1]. //etc 
    I appear to be missing something, I've tried this but it doesn't work can you advise

    PHP Code:
    <html>
    <head>
    <title>A BASIC HTML FORM</title>
    <body>

    <?PHP
     
    $file_handle 
    fopen("csv/pins.csv""r");
     
    while (!
    feof($file_handle) ) {
     
    $line_of_text fgetcsv($file_handle1024);
     

    print 
    '<p><div align="center"><table border cellpadding="2" cellspacing="0" width="676" bordercolor="gray" bordercolordark="gray" bordercolorlight="gray"><tr><td>' $line_of_text[0] . '</td><td>' $line_of_text[1]. '<tr><td>' $line_of_text[2] . '</td><td>' $line_of_text[3]. '<tr><td>' $line_of_text[4] . '</td></tr></table></div>'


    }
     
    fclose($file_handle);
     
    ?>


    </body>
    </html>
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,866
    Rep Power
    6351
    You need to learn some HTML before you try PHP. DIV and P tags cannot be placed inside a table, and a table requires a <table> tag.

    PHP Code:
    <html> 
    <head> 
    <title>A BASIC HTML FORM</title> 
    <body> 
    <table border=1>
    <?PHP 
      
    $file_handle 
    fopen("csv/pins.csv""r"); 
      
    while (!
    feof($file_handle) ) { 
      
    $line_of_text fgetcsv($file_handle1024); 

        echo 
    '<tr><td>' $line_of_text[0] . '</td><td>' $line_of_text[1] . '</td><td>' $line_of_text[2] . '</td><td>' $line_of_text[3] . '</td><td>' $line_of_text[4] . '</td></tr>';


      
    fclose($file_handle); 
      
    ?> 

    </table>

    </body> 
    </html>
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Thanks for your help, I see where I went wrong, sorted now

IMN logo majestic logo threadwatch logo seochat tools logo