如何仅显示我显示的csv文件列标题的几个选定复选框的选定选项

问题描述 投票:0回答:1

  
  <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文件后,它会正确显示带有列标题的数据。但是,如何仅显示带有选中选项的“检查框”确实有麻烦。

View image form如何仅显示所选复选框的所选选项。请帮助。

php csv select checkbox option
1个回答
0
投票

尝试用下面的代码替换完整的foreach($_POST['lang'] as $value){...}部分

foreach ($_POST['lang'] as $key => $value) {

        $method = $package[$key];
        echo "<tr><td>";
        if ($method == 'sum') {
           echo "Sum of " . $value;
        }
        else if ($method == 'mean') {
           echo "mean of " . $value;
        }
        else if ($method == 'mode') {
           echo "mode";
        }
        else {
           echo"no links";
        }
        echo "</td></tr>";
}

希望可以解决此问题

© www.soinside.com 2019 - 2024. All rights reserved.