jeudi 30 janvier 2020

How to display only the selected option for several chosen checkboxes of my displayed csv file column headers

  
  <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/>';
          }
        
           }

          

       }

   }

  

}
?>

enter image description here I am using a form which have check-boxes and select option. Upon import of my csv files using PHP, it displays the data correctly with the column headers. However having real trouble on how to display the CHECKED-boxes with its selected option only.

enter image description here how do I display on the selected option for the selected checkbox. Please help.




Aucun commentaire:

Enregistrer un commentaire