我正在尝试在我的主索引页面上显示最近订单的产品我有这个代码它工作正常,但我想在其中添加订单产品拇指,它存储在ecs_goods
goods_thumb
function index_get_recent_buy_query()
{
$sql = 'SELECT ecs_users.user_name, ecs_order_goods.goods_id,
ecs_order_goods.goods_name, order_info.add_time, order_info.consignee
FROM ecs_users,
(
SELECT order_id, user_id, add_time, consignee
FROM ecs_order_info
ORDER BY ecs_order_info.add_time DESC
LIMIT 0 , 20
) AS order_info,
ecs_order_goods
WHERE order_info.order_id = ecs_order_goods.order_id
AND order_info.user_id = ecs_users.user_id;';
$all = $GLOBALS['db']->getAll($sql);
$ arr [$ idx] ['goods_thumb'] = get_image_path($ row ['goods_id'], $ row ['goods_thumb'],true);
我有goods_id,但我对如何在上面的SQL查询中包含来自ecs_goods
的goods_thumb感到困惑
答案 0 :(得分:0)
这是查询部分。我在ecs_goods
字段中添加了goods_id
表的联接,并在goods_thumb
子句中添加了SELECT
字段。
SELECT ecs_users.user_name, ecs_order_goods.goods_id,
ecs_order_goods.goods_name, order_info.add_time, order_info.consignee, ecs_goods.goods_thumb
FROM ecs_users,
(
SELECT order_id, user_id, add_time, consignee
FROM ecs_order_info
ORDER BY ecs_order_info.add_time DESC
LIMIT 0 , 20
) AS order_info,
ecs_order_goods, ecs_goods
WHERE order_info.order_id = ecs_order_goods.order_id
AND order_info.user_id = ecs_users.user_id
AND ecs_goods.goods_id = ecs_order_goods.goods_id;