我有一個包含 6 個隨機 id 的數組。如何 select * where id not equal to在 php 中執行我的數組?我正在嘗試使用 for 循環,但首先它返回除 之外的所有內容id[0],第二次返回除了 之外的所有內容id[1],依此類推。我的查詢看起來像這樣select * from challenges where id <> id[i]我的數組是catogary_id并且看起來像Array ( [0] => 6 [1] => 2 [2] => 4 [3] => 10 [4] => 3 [5] => 5 [6] => 8 [7] => 1 [8] => 7 )循環for($cnt=0;$cnt<count($cat_id);$cnt++){ $task_id=$catogary_id[$cnt]; $result = mysqli_query($connection,"select * from task id <> $task_id"); $Qno=1; while($row=mysqli_fetch_assoc($result)) { do something here }}
1 回答

長風秋雁
TA貢獻1757條經驗 獲得超7個贊
$sql = "SELECT * FROM task WHERE id NOT IN ( '" . implode( "', '" , $cat_id ) . "' )"; $result = mysqli_query($connection, $sql);
- 1 回答
- 0 關注
- 76 瀏覽
添加回答
舉報
0/150
提交
取消