writing inner join in wpdb

时间:2015-09-17 作者:Mina Ragaie

我在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中

1 个回复
最合适的回答,由SO网友:Mina Ragaie 整理而成

感谢您的时间和@Czersplace,我以双引号开始查询,然后用单引号将其分开,查看echo输出后,我发现Fromtable 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"\');

相关推荐

如何像使用wpdb一样使用MySQL?

根据标题,我需要使用LIKE操作符以编程方式使用$wpdb删除db上的一行。我想使用$wpdb->delete 消除发生的情况,但我不知道如何设置LIKE 操作员,因为在WHERE 它需要一个指定单个值或另一个数组的数组。我问你这个语法是否正确。$wpdb->delete(\'wp_posts\', array(\'post_type\' => \'flamingo_inbound\', \'post_content\' => \'%\'.$mail.\'%\'));提前感谢