Jump to content

finding the maximum number of a column from a csv file


jadeg

Recommended Posts

I have a csv file and I am trying to get the minimum value for a particular column. However I am not getting an exact value even after exploding the values. After I explode and I do a var_dump on it, it produces a different array for each different row; so each value in the column is the first element of a different array. How do I merge this different arrays into one array in order to find the minimum value in the column, or is there any other way to go about it? Below is my code. Any help will be appreciated.

 

 

My code is below and a link to the excel file 

https://www.dropbox.com/s/n7pyv96qv1yv8yc/Example%20SG%20Data.xlsxwhile (($data = fgetcsv($handle, 0, ",")) !== false) {


$table2Add =false;
if($row >=$x && $row <=$y) {
$table2Add=true; }


if($row == 1) {
$table2 .= '<thead><tr>';
$table2 .= '<th></th>';
$table2 .= '<th>Min</th>';
$table2 .= '<th>Max</th>';
$table2 .= '<th>Average</th>';
$table2 .= '</tr></thead><tbody>';


}
else {

if($table2Add) $table2 .= '<tr><th>Voltage</th>';
for($c = 0; $c <= 10; $c++) {
$value = empty($data[$c]) ? " " : $data[$c];

if($c==1) {
var_dump((explode('STRING',$data[$c])));
//$ar=explode('STRING', $data[$c]);

//var_dump(min($ar));

if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
if($c==2) {
if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
if($c==3) {
if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
}

if($table2Add) $table2 .= '</tr>';



if($table2Add) $table2 .= '<tr><th>Current</th>';
for($c = 0; $c <= 10; $c++) {
$value = empty($data[$c]) ? " " : $data[$c];
if($c==4) {
if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
if($c==5) {
if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
if($c==6) {
if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
}

if($table2Add) $table2 .= '</tr>';


if($table2Add) $table2 .= '<tr><th>Power Factor</th>';
for($c = 0; $c <= 10; $c++) {
$value = empty($data[$c]) ? " " : $data[$c];
if($c==7) {
if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
if($c==8) {
if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
if($c==9) {
if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';
}
}

if($table2Add) $table2 .= '</tr>';



}
$row++;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.