我有一个 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> </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/