vendredi 30 janvier 2015

how can store the values of dynamically generated checkboxes in a table?

I have created a table of checkboxes. For each row, the first checkbox can check/ uncheck the rest of the row. Now I need to get the values of all the checkboxes (except from the first checkbox that selects all). From the values of each row I will generate a single number (taking the checkbox values as boolean values where Yes = 1 and No = 0). That will give me a number per row. Then these numbers will be stored in a table that has as many columns as there are rows of checkboxes. Value from first row will be stored in the first column and so on ...


This is the code that generates the table of checkboxes:



<?php
$days = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
echo "<table border = 1px>";
//table header
echo "<tr>";
for ($i = 0; $i < 15; $i++){
echo "<th>";
if($i == 6) {$i++;}
if($i == 1) {echo "Check All";}
else if($i != 0) {
echo $i+6 . ":30 - "; echo $i+7 . ":30";
}
echo "</th>"; }
echo "</tr>";
//checkboxes are created here
for ($x = 0; $x < 6; $x++) {
echo "<tr>";
echo "<td>"; echo $days[$x]; echo '</td>'; //displays days
echo '<td><input type="checkbox" onClick="toggle(this, '.$x.')"/> All</td>'; //creates check all buttons
for ($y = 0; $y < 12; $y++)
echo '<td><input type="checkbox" name="'.$x.'" value="bar1"> Bar 1<br/></td>'; //creates the other buttons
echo "</tr>";
}
echo "</table>";
?>


I am not asking to have it all figured out. Only how to pass the values in my php file. Also, obviously there is a submit button that successfully posts the other data. I have fetched the other values from the other fields (which i haven't included in this code to make it look simpler). The method used is post and they are all stored correctly.


By the way, im using postgresql





Aucun commentaire:

Enregistrer un commentaire