我想从msql中的两个表中获取数据,按日期排序。
$sql = "
SELECT
items.*, invoice.*
FROM
items
JOIN
invoice
ON
items.user_id = invoice.buyer_id
WHERE
items.user_id = '$user_id'"
LIMIT
10
ORDER BY
date;
";
答案 0 :(得分:0)
尝试:
$sql = "SELECT *";
$sql .= " FROM items, invoice";
$sql .= " WHERE items.user_id = invoice.buyer_id";
$sql .= " AND items.user_id = '$user_id'";
$sql .= " ORDER BY date DESC";
$sql .= " LIMIT 10";
最好将它用作预准备语句,而不是在SQL查询中包含变量以避免SQL注入。