PHP file upload and want to get data from the column (Minimum and maximum value)

54 Views Asked by At
$limit = 1;
    $fileHandle = fopen($inputFileName, "r");
    if ($fileHandle === FALSE) {
        die('Error opening ' . $inputFileName);
    }

    // Set up a variable to hold our current position in the file
    $offset = 0;
    while (!feof($fileHandle)) {
        // Go to where we were when we ended the last batch
        fseek($fileHandle, $offset);
        $i = 0;
        while (($currRow = fgetcsv($fileHandle)) !== FALSE) {
            $i++;
            $row = implode('|', $currRow);
            $list = explode('|', $row);
            if (trim($list[0]) == 'System Setup') {
                $fdt = $list[1];
                $prvxdt = date('Y-m-d H:i:s', strtotime($fdt));
            } elseif (trim($list[0]) == 'Probe Card Serial Number:') {
                $prvxbc = substr(trim($list[1]), 0, 10);
            }elseif (trim($list[0]) == 'Probe ID') {
                $dia = substr(trim($list[23]), 0, 23);
            }
            if($i >= $limit)
            {
                //Update our current position in the file
                $offset = ftell($fileHandle);
                //Break out of the row processing loop
                break;
            }
        }
    }

    // Close the file
    fclose($fileHandle);
    $fext = '.csv';

I want to get values from the csv file and Column name is called as Diamemter (um). I already get the column name by this line elseif (trim($list[0]) == 'Probe ID') { $dia = substr(trim($list[23]), 0, 23); }. I want the total Maximum and Minimum values from Diameter (um) column. CSV column and values.

1

There are 1 best solutions below

0
Ken Lee On

If I understand your question correctly, the column you mentioned (column X) is $list[23]

To get the min and max values, you may add the following before your while loop (inner while loop):

// initalize the values
$maxx=0;
$minx=99999999;

and then change

    $dia = substr(trim($list[23]), 0, 23);

to

    $dia = substr(trim($list[23]), 0, 23);
    $dia2=trim($list[23]);
        if ($dia2 > $maxx) { $maxx=$dia2; }
        if ($dia2 < $minx) { $minx=$dia2; }

After the while loop (inner while loop), the $maxx and $minx will be the maximum value and minimum values respectively