简体   繁体   English

PHP-如何选择多个复选框并显示所选复选框中的所有值?

[英]PHP - How can i select multiple check boxes and show all the values from the selected check boxes?

I have one html table with all the values from a specific table, and i want to put an update button to update specific rows 我有一个html表,其中包含来自特定表的所有值,并且我想放置一个update按钮来更新特定行

And i want to update those rows using checkboxes. 我想使用复选框更新这些行。

The user just need to check the selectboxes and click at a button, and this button will display all the information from the rows that were selected. 用户只需要选中选择框并单击一个按钮,该按钮将显示所选行中的所有信息。

I have here a bit of code that i created, but i just can read the last selected box value. 我这里有一些我创建的代码,但是我只能读取最后选择的框值。

I'm using MVC structure, but with my own rules. 我正在使用MVC结构,但有自己的规则。

Here the model, I created the function inside the model: 在此模型中,我在模型内部创建了函数:

$editjo_query = ("SELECT * FROM my_table");

$print_editjo = db_array($editjo_query, 'a+'); //this is a function that i created to    select, ignore please

if(!empty($_POST['editcheck'])){

    $editcheckbox = $_POST['editcheck'];
    $countCheckedit = count($_POST['editcheck']);

    for($i=0;$i<$countCheckedit;$i++) {
        $edit_id = $editcheckbox[$i];

        $editjo_query = ("SELECT * FROM my_table WHERE id=$edit_id");

        $print_editjo = db_array($editjo_query, 'a+'); //this is a function that i created to select, ignore please
     }
}

And this function is being called at the view 并且此函数在视图中被调用

function editjoview($print_editjo){
     foreach($print_editjo as $check){
        echo $check['id'];
     }
}

you are always writing to $print_editjo with $print_editjo = db_array($editjo_query, 'a+'); 您总是使用$print_editjo = db_array($editjo_query, 'a+');来写入$print_editjo $print_editjo = db_array($editjo_query, 'a+'); and you you do not process it. 并且您不处理它。 So in ever for loop you overwrite it, leaving you with the last entry. 因此,在for循环中,您将其覆盖,剩下最后一个条目。 Try this: 尝试这个:

$print_editjo = array();
for($i=0;$i<$countCheckedit;$i++) {
  $edit_id = $editcheckbox[$i];
  $editjo_query = ("SELECT * FROM my_table WHERE id=$edit_id");
  $print_editjo[] = db_array($editjo_query, 'a+');
}

and in your view, iterate over the array $print_editjo rather than just having $print_editjo as the last entry. 并且在您看来,遍历数组$print_editjo而不是仅将$print_editjo作为最后一个条目。

Note: If you would add how exactly the function in your view is called, the help could be more precise. 注意:如果要添加视图中函数的确切调用方式,则帮助可能更加精确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM