【发布时间】:2020-01-31 07:40:42
【问题描述】:
<table border="0" cellspacing="1" cellpadding="1" class="sortable" >
<?php
#read CSV file
$uploadfile = $_SESSION['uploadCsv'];
if (($handle = fopen($uploadfile, "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='standard deviation'>Standard deviation</option>
<option value='mode'>Mode</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>
<input type='submit' value='submit' name='submit'<table></form>";
}
?>
</tbody>
<div style="border:solid 2px red;width:50%;">
<?php
$package = $_POST['method'];
if(isset($_POST['submit'])){
if(!empty($_POST['lang'])) {
foreach($_POST['lang'] as $value){
echo "<tr><td>";
echo " value : ".$value.'<br/>';
echo "</td></tr>";
if(!empty($_POST['method']))
{
foreach($_POST['method'] as $method){
if($method == 'sum')
{
echo "<tr><td>";
echo "Sum of ".$value."";
echo "</td></tr>";
} else if ($method == 'mean')
{
echo "<tr><td>";
echo "mean of ".$value."";
echo "</td></tr>";
}else if ($method == 'mode')
{
echo "<tr><td>";
echo "mode";
echo "</td></tr>";
}
{
echo"no links";
}
//echo "method : ".$method.'<br/>';
}
}
}
}
}
?>
My form image 我正在使用具有复选框和选择选项的表单。使用 PHP 导入我的 csv 文件后,它会使用列标题正确显示数据。但是,在如何仅显示带有所选选项的 CHECKED 框时遇到了真正的麻烦。
View image form 如何仅显示选定复选框的选定选项。请帮忙。
【问题讨论】:
-
展示您的代码而不是图片
-
@AksenP 你好,我已经添加了代码,谢谢。
标签: php csv select checkbox option