Öncelikle, Ben bu olduğunu kabul edeceğiz Bu konuda gitmenin en iyi yolu ama sorununuzu çözecek.
İkincisi, HTML Giriş öğesini type="checkbox"
olarak değiştirmenizi öneriyorum. kontrol edildiği bilmek edebilmek için, aşağıda şuna benzer için kodunuzu ayarlamanız gerekir:
<!-- HTML part -->
<form action="" method="post">
<!-- we need the form as the parent to the table so content can be posted to the server -->
<table ....>
<thead>
<tr>
<th> </th> <!-- we'll put our checkboxes in this column of the table -->
...
</tr>
</thead>
<tbody>
<?php
foreach ($rows as $row) {
?>
<tr>
<td><input type="checkbox" name="chkSelect[]" value="<?php echo $row['id']; ?>" /></td>
....
</tr>
<?php
}
?>
</tbody>
</table>
<button type="submit" name="btnDelete" value="">Delete</button> <!-- This is assuming we're trying to delete the selected items -->
</form>
<!-- HTML end -->
Bu noktada, bizim formu hazır olması; Bu PHP tarafında bir dizi olarak işlenmesine olanak verir, onay kutusu adı ondan sonra []
sahip olduğunu not edin. PHP tarafında
, sadece şöyle normal form işleme yapmanız gerekir:
if (filter_has_var(INPUT_POST, 'btnDelete')) {
$checkedIds = filter_input(INPUT_POST, 'chkSelect', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
// if we loop through the array, we can see the selected item ids
var_dump($checkedIds);
}
Umut bu sorunuzu, mutlu kodlama cevap! ;)
Ve ne denediniz mi? –
Bu, verilerin nasıl düzenlendiğine bağlıdır. Radyo düğmeleri, kullanıcının sadece birini seçebilmesi için tasarlanmıştır, böylece sadece hangisinin seçildiğini görebilirsiniz. Çoklu seçim isteseydi, daha sonra, adının sonuna ve kimliği olarak değere '[]' ekleyerek bir dizi olarak birbirine bağlamak, onay kutularını kullanın '$ _POST [ 'checkbox_name']' yoluyla foreach olabilir. –