PHP数组选择mysql [英] PHP Array to select mysql
本文介绍了PHP数组选择mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个完整的包列表,我希望用户使用复选框进行选择并比较包.用户选择后,我将使用从复选框数组中获取的 packages_id 将所有包数据显示为 .PDF 文件.如何分离数组并注入到mysql select?
I have a whole list of package and I want the user to select using the checkbox and compare the packages. After the user select, I'll use the packages_id which I get from the checkbox array to display all the package data to a .PDF file. How do I separate the array and inject to the mysql select?
$_POST['compare'] 的输出:[14,15,16]
Mysql 查询:
$packages=mysql_query("
select *
from package
where id in (" . implode(',', $_POST['compare']) . ")
LIMIT 4");
推荐答案
这应该对你有用
mysql_query("
select *
from package
where id in (" . implode(',', $_POST['compare']) . ")
");
适当注意清理和验证您的输入
Take proper care to sanitize and validate your inputs
这篇关于PHP数组选择mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文