gpt4 book ai didi

php - 多个 WHERE AND 查询 - Mysql/PHP

转载 作者:行者123 更新时间:2023-11-29 06:57:05 26 4
gpt4 key购买 nike

尝试将一个查询的结果放入另一个查询的 WHERE 语句中:

$query1 = "SELECT DISTINCT company_id FROM location WHERE state = 'XX'";
$result1 = mysql_query($query1) or die(mysql_error());
while($row1 = mysql_fetch_array($result1)) {
//Collect WHERE STATEMENT HERE
}

我试过以下方法:

$q1 = "SELECT company FROM company WHERE id = '16', id = '7' ORDER BY company";
$q1 = "SELECT company FROM company WHERE id = '16' AND id = '7' ORDER BY company";
$q1 = "SELECT company FROM company WHERE id = '16' && id = '7' ORDER BY company";

与其他变体一起

Google 只提供了多个 WHERE AND 如果使用不同的表名,而不是相同的。有人有任何指示吗?

最佳答案

通用代码:

$ids = array (
[0] => 2
[1] => 4
[2] => 19
[3] => 16
);

$ids = join(',',$ids);
$sql = "SELECT * FROM company WHERE id IN ($ids)";

引用:same example

关于php - 多个 WHERE AND 查询 - Mysql/PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12087152/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com