Как вы можете видеть на изображении здесь , я использую форму с флажками и опцией выбора. При импорте моих CSV-файлов с использованием PHP данные отображаются правильно с заголовками столбцов. Также отображаются поля CHECKED только с выбранной опцией.
мой csv-файл:
year, Exports of goods(F.O.B), Domestic exports, Re-exports.
1, 5, 10,20
1, 5, 10, 20
1, 5, 10, 20
1, 5, 10, 20
Спасибо.
<!DOCTYPE html>
<html>
<head>
<title>Start1</title>
</head>
<body>
<table border="0" cellspacing="1" cellpadding="1" class="sortable" >
<?php #read CSV file
if (($handle = fopen("sample1.csv", "r")) !== false) {
$mycsv = array();
while (($data = fgetcsv($handle, 1000, ",")) !== false) {
$mycsv[] = $data;
}
fclose($handle);
#Find the length of the transposed row
$row_length = count($mycsv);
echo "<form method='post' action=''><table><tr>";
echo "<th><input type='checkbox' onClick='toggle(this)' /> Select/Deselect All<br/>
</th>";
echo "<th>Column</th>";
echo "<th>Filter</th>";
echo "</tr>";
#Loop through each row (or each line in the csv) and output all the columns for that row
foreach ($mycsv[0] as $col_num => $col) {
echo "<tr>";
for ($x = 0; $x < 1; $x++) {
echo "<td><input type='checkbox' name='lang[]' value='" . $mycsv[$x][$col_num] . "' ></td>";
echo "<td align='center'>" . $mycsv[$x][$col_num] . "</td>";
echo "<td>
<select name='method[]' >
<option value=''>Choose</option>
<option value='sum'>Sum</option>
<option value='mean'>Mean</option>
<option value='average'>Average</option>
<option value='highest'>Highest Value</option>
<option value='lowest'>Lowest Value</option>
</select>
</td>";
echo "</tr>";
}
}
echo "<tr>";
echo "<td><input type='checkbox' name='lang[]' ></td>";
echo "<td align='center'><input type='text' name='own_column' placeholder='Type your new column here'><br></td>";
echo "<td><input type='text' name='own_column' placeholder='Own formula'><br></td>";
echo "</tr>";
//echo "<tr>";
//echo "<td colspan='3' align='center'><input type='submit' name='Order'/></td>";
//echo "</tr>";
echo "<tr>";
echo "<td colspan='3'><div class='wrapper'><br/><br/><input type='button' class='button' value='Input Button'>
</div></td>";
echo "</tr>
<tr><td><input type='submit' value='submit' name='submit'</td></tr><table></form>";
$post_data = $_POST["lang"];
//$SelectedOption = $_POST['demo'];
for ($i = 0; $i < count($post_data); $i++) {
//echo "Selected : " . $post_data[$i]."</br>" ;
}
$row_length = count($mycsv);
$col_length = count($post_data);
$flag = true;
$sum = array();
foreach ($mycsv[0] as $key => $value) {
foreach ($post_data as $search_term) {
if (strcasecmp(trim($value), trim($search_term)) == 0) {
for ($row = 0; $row < $row_length; $row++) {
array_push($sum, $mycsv[$row][$key]);
if ($row == 0) {
echo "<tr>";
echo "<th colspan=100%>" . $mycsv[0][$key] . "</th>";
echo "</tr>";
} elseif ($row == 1) {
//echo "<td>" . $mycsv[$row][$key] . "</td>";
//echo "array sum =".array_sum($sum)."";
}
//echo " array sum =".array_sum($sum)."] ";
}
$method = $_POST["method"];
$method = $method[$key];
echo "<tr><td>";
if ($method == 'sum') {
echo "Sum of " . $value;
} elseif ($method == 'mean') {
echo "mean of " . $value;
} elseif ($method == 'average') {
echo "average of " . $value;
} elseif ($method == 'highest') {
echo "highest value of " . $value;
} elseif ($method == 'lowest') {
echo "lowest value of " . $value;
} else {
echo " Choose a method ";
echo "</td></tr>";
}
}
}
}
} ?>
</table>
</body>
</html>