gpt4 book ai didi

php - WP环境下内连接SQL,where id=id

转载 作者:行者123 更新时间:2023-11-29 10:49:17 25 4
gpt4 key购买 nike

你好, friend ,我有一个问题。我的 id 是“28”,我只想显示该 id 的位置及其第一个对象。我怎样才能生成这种类型的 SQL?

WP SQL:

$rows = $wpdb->get_results( 
"SELECT hotels.id,hotels.hotel,reviews.hotel_id,reviews.id
FROM hotels
INNER JOIN reviews ON hotels.id = reviews.hotel_id" );
var_dump($rows);

var_dump

 array (size=4)
0 =>
object(stdClass)[710]
public 'id' => string '28' (length=2)
public 'hotel' => string 'xxxxx' (length=14)
public 'hotel_id' => string '17' (length=2)
1 =>
object(stdClass)[709]
public 'id' => string '29' (length=2)
public 'hotel' => string 'xxxxxx' (length=14)
public 'hotel_id' => string '17' (length=2)

最佳答案

使用 WHERE 子句

SELECT hotels.hotel,reviews.hotel_id,reviews.id 
FROM hotels
INNER JOIN reviews ON hotels.id = reviews.hotel_id
WHERE reviews.id = 28

关于php - WP环境下内连接SQL,where id=id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44040327/

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