Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint first 3 columns of CSV file in table format in PHP upon file upload
    primarykey
    data
    text
    <p>I am new to PHP and I am stuck with this problem.</p> <pre><code>$mimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv'); if (((in_array($_FILES['uploadedfile']['type'],$mimes))) &amp;&amp; ($_FILES["uploadedfile"]["size"] &gt; 0)) { $filename = $_SESSION['username'].$_FILES["uploadedfile"]["name"]; move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],"./uploads/".$filename); echo "Stored in: " . "./uploads/" .$filename; echo "&lt;br /&gt;\n"; echo 'Daylight hours will be calculated for this latitude : '.$_POST['latCSV']; echo "&lt;br&gt;"; //print out uploaded file.csv echo "&lt;table BORDER=1&gt;\n\n"; echo " &lt;tr&gt;&lt;th&gt;AvgCrown&lt;/th&gt;&lt;th&gt;MinCrown&lt;/th&gt;&lt;th&gt;MaxCrown&lt;/th&gt;&lt;th&gt;dateLogged&lt;/th&gt;&lt;th&gt;DaylightHours&lt;/th&gt;&lt;/tr&gt;"; echo "&lt;tbody id='tblBdyLoggedData'&gt;"; $f = fopen("./uploads/" .$filename, "r"); $i=0; //just a counter while (($line = fgetcsv($f)) !== false) { echo "&lt;tr&gt;"; foreach ($line as $cell) { // Save the value before you output $lastColValue = htmlspecialchars($cell); //unset($lastColValue[3]); echo "&lt;td&gt;" . $lastColValue . "&lt;/td&gt;"; } //checking if date is valid checkDateString($lastColValue); // If you want to store all log dates in an array: $logDates[] = $lastColValue; $firstlogDate = $logDates[$i]; echo "&lt;td&gt;" . checkDateString($lastColValue) . "&lt;/td&gt;"; //call function using firstlogDate for every row echo "&lt;td&gt;" . calcDaylight($firstlogDate,$_POST["latCSV"]) . " &lt;/td&gt;"; echo "&lt;/tr&gt;\n"; $i = $i+1; } fclose($f); echo "&lt;/tbody&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;"; } </code></pre> <p><strong>I would like to get print only the first 3 columns of the CSV file upon file upload</strong> as the two other will be calculated using respective functions. Datelogged will be taken from the csv and reformated properly and daylight Hours is also calculated from datelogged.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload