jeudi 30 mars 2017

How show-hide columns from table with checkbox?

I want to show or hide a column in my table using a checkbox. i try to use datatables plug-in but it doesnt'work. Is there a simple solution with jquery? I found a useful code (http://ift.tt/2nCE0hW) but I don't know how assign a class to "th" to use it. Do you know another solutions?

<?php
$dbLink = mysqli_connect('localhost', 'root', '');
mysqli_select_db($dbLink, 'projects');
$sql = "SELECT relation.id_pers, relation.enroll_year, course.course_description, course_type.type_description FROM relation JOIN course ON relation.id_course=course.id_course JOIN course_type ON course_type.id_type=course_type.id_type LIMIT 15";
$result = mysqli_query($dbLink, $sql) or die(mysql_error());
// Print the column names as the headers of a table
echo "<table id='example'><thead>";
for($i = 0; $i < mysqli_num_fields($result); $i++) {
    $field_info = mysqli_fetch_field($result);
    echo "<th>{$field_info->name}</th>";
    }
 echo "</thead>";
// Print the data
while($row = mysqli_fetch_row($result)) {
    echo "<tr>";
    foreach($row as $_column) {
        echo "<td>{$_column}</td>";
    }
    echo "</tr>";
}
echo "</table>";
?>

And this is my checkbox :

    <section>
   <ul>
      <li>
         <input type="checkbox" name="check[]" id="option"><label for="option">Matricola</label>
         <ul>
            <li><label class="suboption"><input type="checkbox" id="id_stu" class="subOption"> ID studente</label></li>
            <li><label class="suboption"><input type="checkbox" class="subOption"> corso di studi</label></li>
            <li><label class="suboption"><input type="checkbox" class="subOption"> anno di iscrizione</label></li>
         </ul>
      </li>
   </ul>
</section>




Aucun commentaire:

Enregistrer un commentaire