z.abasi z.abasi - 1 year ago 62
SQL Question

How to understand who checkbox is selected?

i want to select a lot row of my database and have checkbox to any of rows that the user can choose any of them.then i should update database according to user choice, but i can't understand who of this checkbox is selected.

thanks a lot...
the semicode is here:

$query = "Select * mytable limit 30;";
$res = $mysql->ExecuteStatement (array ());
echo '<form method="post" action=""> ';
while ($rec=$res -> fetch())
echo '<input type="checkbox" id="$b" name="checkboxName[]" value="yes"/>';
$checkboxID = "number_".$rec["ID"].":";
echo $checkboxID;
echo $rec["column1"]."</br>";

if(isset($_POST['formSubmit'])) //this code just get us how many of checkbox are chosen not who are chosen
foreach($_POST['checkboxName'] as $selected)
echo $selected."</br>";


Answer Source

Try some thing like this:

Provide a class to all checkboxes:

<input type="checkbox" class="MyChkbox" id="$b" name="checkboxName[]" value="yes"/>';

In JS:

        var checkedId = $(this).attr('id');
        // checkedId will contain the checked checkbox id in it. Use it as per your need