0

我想在创建查询时获得一些帮助,以从共享信息的三个不同表中获取信息。我的第一张桌子是:

auctions
id title description user_id(who posted it)

我的第二张桌子是:

bids
id user_id bid auction_id owner_id

我的第三张桌子是:

users
id username X XX XXX XXXX 

...我的 SQL 如下,但它没有返回任何结果:

SELECT auction_bids.user_id AS applicant, auction_bids.*, auctions.title FROM auction_bids, auctions
        WHERE auctions.user_id=".$_SESSION['userid']."  
        INNER JOIN users ON auction_bids.user_id = users.id 
        WHERE auction_bids.owner_id = ".$_SESSION['userid']."

我需要的是捕获拍卖的标题、出价的用户名和出价。拍卖必须由拥有 $_SESSION['userid'] 的用户出价并发布。任何帮助表示赞赏。

4

2 回答 2

1

您有两个不同的“where”语句,可能只需要合并;

选择auction_bids.user_id 作为申请人,auction_bids.*,auctions.title FROMauction_bids,auctions INNER JOIN users ON auction_bids.user_id = users.id WHEREuction_bids.owner_id = ".$_SESSION['userid']." AND auctions.user_id=".$_SESSION['userid']。"

但是,我不确定这是否真的是您想要的,因为它只会返回特定用户既“拥有”该项目又对其出价的记录(均基于用户 ID 会话),而不是显示来自的所有记录对用户“拥有”的物品出价的不同人。

就像是: ?选择auction_bids.user_id AS 申请人,auction_bids.*,auctions.title FROMauction_bids,auctions INNER JOIN users ON auction_bids.user_id = users.id,WHERE auction.owner_id = ".$_SESSION['userid']."

希望这会为您指明正确的方向!

于 2013-06-29T08:36:39.657 回答
0

您有 2 个 where 子句,这是不正确的。我已根据您的要求修改了您的查询。

SELECT auction_bids.user_id AS applicant, auction_bids.*, auctions.title 
FROM auction_bids, auctions
        INNER JOIN users ON auction_bids.owner_id = users.id 
        WHERE auction_bids.owner_id = ".$_SESSION['userid']."
        AND auctions.user_id=auctions_bids.owner_id  
于 2013-06-29T08:16:41.673 回答