在MySQL中,如何使用其他过滤器获取基于PHP数组的数据?



说,这是我的php数组。

postids = Array
(
[0] => 2172
[1] => 383
[2] => 2915
[3] => 677
[4] => 1289
[5] => 1654
[6] => 2252
[7] => 2366
[8] => 2998
[9] => 2442
[10] => 1246
)

现在在 mysql 表 (t1( 中看起来像这样。

|postid|type|switch|
|1|A|0|
|2|A|1|
|3|A|0|
...
|383|A|0|
...
|1246|A|1|
...
|2172|A|1|
...
|2442|A|0|

所以,我想选择类型为"A"的 postid,其中 switch = 1 并按我的 php 数组排序,并包括我的数组中的 post id。

那么,有没有像这样的查询

select postids from t1 where type = 'A' and switch = 1 and postids = {<?php echo postids; ?>}

我如何实现这一点?

您可以在 WHERE 中使用逻辑条件,

SELECT * FROM table WHERE type='A' AND switch='1' 

最新更新