Jump to content

Creating a mini auction for learning purposes - stuck with INNER JOIN problem


adrian28uk

Recommended Posts

I have decided to have a crack at creating a mini auction site in my spare time, simply out curiosity and something that I can learn from in the future.

 

I have created two simple tables, one for auctions and the for bids and manaully populated this through PhpMyAdmin.

For trial purposes Auction 21 has 3 bids on it.

 

I have managed to join the two tables together using the INNER JOIN statement and can output the results of the auctions.

 

$result = mysql_query("SELECT * FROM auctions a INNER JOIN bids b ON a.auction_id = b.auction_id GROUP BY a.auction_id");

 

I am trying to order the bid_amount in the bids table to show the highest bid, but what it is doing is just showing me the first. Auction 21 has 3 bids and 57.00 is the highest bid.

 

auction_id      auction_title            Start Bid      Last Bid

21                 Test auction                0.01             23.00

 

Here are my tables

 

// auctions

auction_id

auction_title

start_price

 

// bids

auction_id

member_id

bid_amount

bid_date

 

Try:

 

"SELECT * FROM auctions a INNER JOIN bids b ON a.auction_id = b.auction_id GROUP BY a.auction_id ORDER_BY b.bid_amount DESC"

 

or

 

"SELECT * FROM auctions a, bids b WHERE a.auction_id = b.auction_id GROUP_BY a.auction_id ORDER_BY b.bid_amount DESC"

 

 

Untested

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.