mysqliを使用して'n'ユニオンを実行する必要があります(nはユーザー入力に基づいて変更されます)。例えば:
select a from b where a=c[1]
UNION
select a from b where a=c[2]
...
UNION
select a from b where a=c[n]
これを繰り返し行う方法はありますか?そのようなもの:for(i = 1; i
注:データベースで実行できるのはselectクエリのみです
組合の必要はありません
数値のa
場合は
$c = array(1,2,3);
$c = array_filter(array_map('intval',$c));
$in = implode(',',$c);
$sql = "select a from b where a IN ($in)";
文字列のアイデアはほとんど同じです。
常に必要な場合はselect a from b where a = dynamicvalue
、dynamicValueを一時テーブルに保存するか、次のようなクエリを使用できます。
SELECT a FROM b WHERE a IN(SELECT c from x WHEREclause = anys)