handling checked checkboxes PHP

前端 未结 3 1995
一个人的身影
一个人的身影 2021-01-25 01:47

I have a table that takes data from the database like so: (Is not a form)

if (mysql_num_rows($result)) {
        echo \"
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-25 02:06

    You would need to do some AJAX or a form submit to pass that checkbox data to PHP for processing.

    But before you can do that, you would need to include a value attribute on those checkboxes. Currently, $_POST['mark'] (if you used POST to submit the form) would be a 0-based array of the checked checkboxes (and only the checked ones).

    I would recommend outputting the user id as the value of checkbox to help out with identifying the marked users.

    Then you could do

    foreach ($_POST['mark'] as $marked) {
        // $marked would contain the value attribute of the checked checkboxes
        // and you could run a SQL query for each value of $marked.
    }
    

提交回复
热议问题