从sql语句返回多行

问题描述:

我想从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&quot ;;

foreach($ _POST [checkbox] as $ check){

$ sql。="或者id = $ check&quot ;;

}


我只是认为在一个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&quot ;;

foreach(
sql = "select * from rows WHERE 1 ";
foreach (


_POST [checkbox] as
_POST[checkbox] as


check){
check){