Witam! Tworzę stronę i mam następujący problem. Muszę masowo pobrać wartości checkboxów i wysłać je do bazy danych. Totalnie nie mam pomysłu jak to zrobić i w jakim języku. Proszę o pomoc/wskazówkę/rozwiązanie.
Próbowałem tak:
Nadałem checkboxom id w pętli w php.
for ($i = 1; $i<=$ile_rekordow; $i++)
{
$zapytanie = $polaczenie -> query("SELECT * FROM klasa2 WHERE nr_dziennik = $i");
$dane = $zapytanie -> fetch_assoc();
echo '<table border = 1 rules = all><tr><td style = "width: 160px">'; echo $dane["imie_nazwisko"]; echo"</td>";
echo'<td class = "larger"><input type = "checkbox"'.'id = "1_'.$i.'"'; if ($dane["wrzesien"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "2_'.$i.'"'; if ($dane["pazdziernik"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "3_'.$i.'"'; if ($dane["listopad"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "4_'.$i.'"'; if ($dane["grudzien"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "5_'.$i.'"'; if ($dane["styczen"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "6_'.$i.'"'; if ($dane["luty"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "7_'.$i.'"'; if ($dane["marzec"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "8_'.$i.'"'; if ($dane["kwiecien"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "9_'.$i.'"'; if ($dane["maj"] == 1) echo "checked ";echo"></td>";
echo'<td class = "larger"><input type = "checkbox"'.' id = "10_'.$i.'"'; if ($dane["czerwiec"] == 1) echo "checked ";echo"></td>";
echo "</tr>";
echo'</table>';
}
A następnie onclick() submita w formularzu wykonało by skrypt.
for (i = 1; i<=24; i++)
{
for (j = 1; j<=10; j++)
{
document.getElementById(j+"_"+i).checked;
}
}
Nie dość, że nie działało albo odczytywanie wartości, albo nadawanie id, to jeszcze nie mam zielonego pojęcia jak miałbym przesłać dane z jsa do bazy.