我在wordpress中编写SQL内部连接语法时遇到了一个问题,这种逻辑肯定会起作用,我在phpmyadmin中尝试过,效果很好
SELECT booking_calendars.cal_name
FROM booking_calendars
INNER JOIN booking_reservation
ON booking_calendars.id = booking_reservations.calendar_id
WHERE status LIKE \'pending\'
但wordpress中没有
$pending_reservations = $wpdb->get_results("
SELECT booking_calendars.cal_name
FROM\'.$wpdb->prefix.\'booking_calendars AS booking_calendars
INNER JOIN\' . $wpdb->prefix.\'booking_reservation AS booking_reservations
ON booking_calendars.id = booking_reservations.calendar_id
WHERE status LIKE \'pending\'");
然后
echo "<h2>Pending Reservation: </h2><br>";
var_dump( $pending_reservations);
if($pending_reservations>0)
{
foreach ( $pending_reservations as $pending_reservation )
{
echo "<label>". $pending_reservation->cal_name."</label><br>";
}
}else{
echo "<label>No Pending Reservation</label><br>";
}
I var\\u转储
$pending_reservations
它回来了
array(0) { }
在wordpress中
最合适的回答,由SO网友:Mina Ragaie 整理而成
感谢您的时间和@Czersplace,我以双引号开始查询,然后用单引号将其分开,查看echo输出后,我发现From
和table name
这是正确的方法
$pending_reservations = $wpdb->get_results(\'
SELECT booking_calendars.cal_name
FROM \'.$wpdb->prefix.\'booking_calendars AS booking_calendars
INNER JOIN \'. $wpdb->prefix.\'booking_reservation AS booking_reservations
ON booking_calendars.id = booking_reservations.calendar_id
WHERE status LIKE "pending"\');