Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:50:43+00:00 2026-06-11T03:50:43+00:00

I have a script that displays the csv file with 2 colums from google

  • 0

I have a script that displays the csv file with 2 colums from google drive to the table

 <?php
            // Connection class for parsing CSV file
            require_once "FGetCSV.php";
            $shs = new File_FGetCSV;

            // Open the CSV file to Google Drive
            $cfg_File = 'link to csv file in gd';
            $f = fopen($cfg_File, "r") or die("Can not open \"$cfg_File\" - ".$php_errormsg);

            // Output CSV file as a table
            $out[]="<table class=\"tb\">";

            $i = 0;
            while ($data = $shs->fgetcsv($f, 65536, ",")) {
                $i++;
                if ($i == 1) {
                    $out[] = "<thead><tr>";
                    $out[] = "<td class=\"header-tb\">$data[0]</td><td class=\"header-tb\">$data[1]</td>";
                    $out[] = "</tr></thead><tbody>";
                }
            else {
            $out[] = "<tr>";
            $out[] = "<td>$data[0]</td><td>$data[1]</td>";
            $out[] = "</tr>";
            }
            }
            $out[] = '</tbody></table>';
            fclose($f);
            echo implode('',$out);
 ?>

How can I improve the script so that it determined the number of columns in the csv file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:50:45+00:00Added an answer on June 11, 2026 at 3:50 am

    So to dynamically detect the column size

    $i = 0;
    $columns = 0;
    while ($data = $shs->fgetcsv($f, 65536, ",")) {
      $i++;
      if ($i == 1) {
        $columns = count($data);
        $out[] = "<thead><tr>";
        // iterate over columns
        for($c=0;$c<$columns;$c++) {
          $out[] = "<td class=\"header-tb\">".$data[$c]."</td>";
        }
        $out[] = "</tr></thead><tbody>";
      }
      else {
        $out[] = "<tr>";
        // iterate over columns
        for($c=0;$c<$columns;$c++) {
          $out[] = "<td>".$data[$c]."</td>";
        }
        $out[] = "</tr>";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic PHP script that displays the file contents of a directory.
I have the script shown below that displays a list of records from a
I have a PHP script that displays an image(according to the current time) and
So I have this php script that output an html table with data about
I have a script that pulls an image from SQL Server and displays it
Possible Duplicate: Php.Advance weekly calendar one week I have written a script that displays
I have a php script that displays a web form to the user. When
I am trying to have a php script that displays a url with user
I have a script that displays countries in different languages. For example United Kingdom
I have script that reads remote file content and writes it to local server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.