我没有数据库查询经验,但我试图从MySQL获取这些数据:
$query->select(array($db->quoteName('userid')));
$query->select(' DATEDIFF(expires, now()) as dayleft');
$query->from($db->quoteName('product_order_status'));
$query->where($db->quoteName('userid') . ' LIKE '. $userID);
$query->where($db->quoteName('active') . ' LIKE '. '1');
$query->from($db->quoteName('product_orders'));
$query->where($db->quoteName('processor') . ' LIKE '. 'paypal');
我想要得到的是 -
来自 product_order_status 表
来自 product_orders 表
如何正确地进行此查询以便我可以获得PayPal为当前登录用户处理的活动订单?
答案 0 :(得分:1)
我不熟悉您用来生成这些查询的PHP库,但您的答案可能如下所示:
$query->select(array($db->quoteName('product_order_status.userid')));
$query->select(' DATEDIFF(expires, now()) as dayleft');
$query->from($db->quoteName('product_order_status'));
$query->where($db->quoteName('product_order_status.userid') . ' LIKE "'. $userID . '"');
$query->where($db->quoteName('active') . ' LIKE '. '1');
$query->from($db->quoteName('product_orders'));
$query->where($db->quoteName('processor') . ' LIKE '. '"paypal"');
或者可能这样:
$query->select(array('`product_order_status`.`userid`'));
$query->select(' DATEDIFF(expires, now()) as dayleft');
$query->from($db->quoteName('product_order_status'));
$query->where('`product_order_status`.`userid`' . ' LIKE "'. $userID . '"');
$query->where($db->quoteName('active') . ' LIKE '. '1');
$query->from($db->quoteName('product_orders'));
$query->where($db->quoteName('processor') . ' LIKE '. '"paypal"');