Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将复选框列添加到具有从php中的数据库动态生成的值的表中_Php_Html - Fatal编程技术网

将复选框列添加到具有从php中的数据库动态生成的值的表中

将复选框列添加到具有从php中的数据库动态生成的值的表中,php,html,Php,Html,我想在我的表中添加一列,该列将包含复选框,如果选中该列,我可能能够获取所选行数据的所有id 这是我的密码: <table> <thead> <th>Name</th> <th>Company</th> <th>Address</th> </thead> <tbody> <?ph

我想在我的表中添加一列,该列将包含复选框,如果选中该列,我可能能够获取所选行数据的所有id

这是我的密码:

<table>
    <thead>
        <th>Name</th>
        <th>Company</th>
        <th>Address</th>
    </thead>
    <tbody>
            <?php 
                $sql = "SELECT * FROM Client";
                $qry = mysql_query($sql);

                while($row = mysql_fetch_array($qry)){
                    echo "<tr>
                            <td>$row[name]</td>
                            <td>$row[company]</td>
                            <td>$row[address]</td>
                        </tr>";
                }
    </tbody>
</table>

名称
单位
地址

这取决于您的数据库表布局。在最好的情况下,您有一个名为company_id的自动递增列。否则,很难区分行。

尝试这样做

while($row = mysql_fetch_array($qry)){
                echo "<tr>
                        <td><input type='checkbox' id='$row[id]' name='$row[id]'></td>
                        <td>$row[name]</td>
                        <td>$row[company]</td>
                        <td>$row[address]</td>
                    </tr>";
            }
while($row=mysql\u fetch\u数组($qry)){
回声“
$row[名称]
$row[公司]
$row[地址]
";
}

只需添加一个“另一个”,创建一个复选框数组并存储值

while($row = mysql_fetch_array($qry)){
   echo "<tr>
            <td>$row[name]</td>
            <td>$row[company]</td>
            <td>$row[address]</td>
            <td><input type='checkbox' name='row_id[]' id='rowid_<?php echo $id ?>' value='<?php echo $id ?>' />
         </tr>";
}

但它将以数组格式返回选定的复选框值。您可以使用循环访问所有元素,也可以使用
内爆()
函数作为字符串使用。

我的答案有一个条件,即它需要该表中的id字段,并且可以自动递增或手动输入。您希望如何处理这些值?它很容易使用(id-主键字段),就像您使用(名称、公司和地址)一样,只需添加$row[id]请在表中用id替换id。在此之后,您可以将其替换为()。这只是一个模式而不是确切的答案。我希望选择这些id,以便能够执行删除功能,删除所有选定的值。您可以发布表列吗?ClientId、名称、公司、地址这些是我在数据库中的列。将其添加到while循环中。在这之后,您需要一个表单来发送选定的复选框,或者您可以依赖javascript。谢谢!我要试试那个。
$rowid      = $_POST['row_id'];