php - mysql 查询的输出结果依赖于 MySQL 数组中选定的行

标签 php mysql session checkbox

我有一个 PHP 页面,它输出 MySQL 查询的结果。每个输出行都有一个复选框。用户将检查所需的行并单击查看详细信息按钮。然后我想显示取决于用户选择的 MySQL 查询结果。

SELECT * FROM table WHERE id = 'selected Checkbox's'

我的PHP页面如下:

<?php
    mysql_connect("localhost", "hulamin_hulamin", "Hulamin2011")or die("cannot connect");    
    mysql_select_db("hulamin_loc")or die("cannot select DB");
    $sql="select loadid as `Order Number`, LOCStatus as `Load Status`,count(loadid) as `Number of Cases`,sum(`Gross Mass`) as `Total Weight`, customer as Customer, transporttypename as `Transport Type` from despgoods_alldetails where loadid > 0 group by loadid";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);       ?> <table border=0>
    <tr>
        <td>
            <form name="form1" method="post">
                <table border=1
                    <tr>
                        <th>&nbsp;</th>
                        <th width=150>Order number</th>                     
                        <th width=150>Status</th>  
                        <th width=150>Number of Cases</th>
                        <th width=130>Total Weight</th>
                        <th width=300>Customer</th> 
                        <th width=150>Transport Type</th> 
                                            </tr> <?php
    while($rows=mysql_fetch_array($result)){ ?>
                    <tr>
                        <td><input type="checkbox" name=check[]  value="<?php echo $rows['Order Number']; ?>"></td>
                        <td><?php echo $rows['Order Number']; ?></td>
                        <td><?php echo $rows['Load Status']; ?></td>
                        <td><?php echo $rows['Number of Cases']; ?></td>
                        <td><?php echo $rows['Total Weight']; ?></td>
                        <td><?php echo $rows['Customer']; ?></td>
                        <td><?php echo $rows['Transport Type']; ?></td>

                    </tr>                                   

<?php
    } ?>
                    <tr>
                        <td colspan=7><input name="ViewDetails" type="submit" id="ViewDetails" value="ViewDetails"></td>
                    </tr>
                    <?php



                            $check=$_POST['check'];

                        if($_REQUEST['ViewDetails']=='ViewDetails'){

                        }
                   mysql_close(); ?> </table> </form> </td> </tr> </table>

单击提交按钮后,我希望运行查询并输出结果

select * from desp_goods where loadid=$checkboxes

如有任何帮助,我们将不胜感激。

谢谢, 瑞安

最佳答案

复选框的 html 是

<input type="checkbox" name="ids[]" />

你的帖子 $_POST 数组是这样的

$ids = array(1,2,3,4);

MySQL 查询应该是:

select * from desp_goods where loadid IN (implode(',', $ids))

关于php - mysql 查询的输出结果依赖于 MySQL 数组中选定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7672989/

相关文章:

PHP 锂 : Filtering an existent DocumentSet and get first Match

php - 使用 jquery 过滤组合框

php - NOT IN 不工作 MYSQL

php - 如何在 MySQL 中存储包含引号的数据

mysql - 使用 BCrypt 进行身份验证在使用 mysql 数据库时不保存 hashed_pa​​ssword

php - 结果集(存储过程)为空时获取列名(Laravel)

asp.net - 存储 ASP.NET session 变量的最佳解决方案是什么? StateServer 还是 SQLServer?

php - 无法与主机 smtp.gmail.com [连接被拒绝 #111] 在 Laravel 5.6 电子邮件发送中建立连接

session - 使用 Dart 进行用户身份验证的教程

node.js - express session存储在redis中用于匿名