从sql语句返回多行 [英] return multiple rows from sql statement
问题描述
我想从sql行的表格中过滤掉一堆行
结果。
i在每行上都有一个复选框,名为checkbox [x]
(x =当前行ID)
i将提交表单并获取所有已检查的行和
过滤掉未检查的行。
所以,如果我有10行,我检查了3行,那么当我提交
表格时,只会显示3行。
我想知道在sql
语句中调用这些行的最佳方法是什么。
我会循环通过检查的行并使用OR条件将它们添加到
WHERE STATEMENT?
从id = 3或id = 2的行中选择*或者id = 6或者id = 10
所以基本上我会用php代码做这样的事情。
$ sql =" select * from rows WHERE 1" ;;
foreach($ _POST [checkbox] as $ check){
$ sql。="或者id = $ check" ;;
}
我只是认为在一个sql中使用这么多OR条件很慢
声明,但我无论如何都想不到这样做。
我想这样做的方式好吗?
感谢您的帮助
i would like to filter out a bunch rows from a table of sql row
results.
i have a checkbox on each row named checkbox[x]
(x = the current row id)
i will submit the form and take all the rows that are checked and
filter out the ones that are not checked.
so if i had 10 rows and i checked 3 of them then when i submit the
form only those 3 rows will show up.
I was wondering what was the best way to call those rows in the sql
statement.
Would i just loop through the rows that were checked and add them to
the WHERE STATEMENT using the OR condition?
select * from rows where id = 3 or id = 2 or id = 6 or id = 10
so basically i would do something like this with the php code.
$sql = "select * from rows WHERE 1 ";
foreach ($_POST[checkbox] as $check){
$sql .= " OR id = $check";
}
I just think its slow to use so many OR conditions in one sql
statement, but i cant think of anyway else to do this.
Is the way i want to do this a good way?
Thanks for your help
推荐答案
sql =" select * from rows WHERE 1" ;;
foreach(
sql = "select * from rows WHERE 1 ";
foreach (
_POST [checkbox] as
_POST[checkbox] as
check){
check){
这篇关于从sql语句返回多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!