SQL连接多个表错误

时间:2013-12-09 16:27:55

标签: php mysql

我正在尝试执行SQL查询,该查询将从不同的表中获取详细信息。

E.G。

Products { ID, Title, Description, Price}
Offering { ID, ProductId, Price, UserID, Condition}
User     { ID, Username, etc}

我希望它能显示返回特定产品的所有产品。每种产品都可以有多种产品。用户可以提供产品。 (当有人列出他们自己要出售的物品时,提供的产品)例如,该产品将是一本哈利波特书,任何用户都可以将该书的副本列为待售品。

$offering = mysqli_query($con, SELECT offering.price, offering.comment, offering.productid, user.username
FROM offering
INNER JOIN username on (offering.userid=offering.userid)
WHERE offering.productid = $productid );

这应该使用已放置产品的用户的用户名将每个产品作为一行返回。

目前,每次使用不同的用户ID显示产品时,它会返回相同产品的多行。

我不确定我是否已正确解释了它!

1 个答案:

答案 0 :(得分:1)

$offering = mysqli_query($con, "SELECT offering.price, offering.comment,
offering.productid, user.username from offering,user where user.ID=offering.UserID;");