title: Getting highest bidder
body: <p>I have a query I have written for my auction application. But the issue I'm facing is getting the highest bidder for a particular item.</p>
  
  <p>Below is my query:</p>
  
  <pre><code>$query = "SELECT  auctions.auctionId, quantity, startPrice, reservePrice, startTime,
  endTime, itemName, itemBrand, itemDescription, items.image, auctions.views,
  item_categories.categoryName as subCategoryName, superCategoryName,
  item_categories.superCategoryId, item_categories.categoryId,
  users.userId, users.firstName, users.lastName, bids.userId AS mbid,
  conditionName, countryName, COUNT(DISTINCT (bids.bidId)) AS numBids,
  COUNT(DISTINCT (auction_watches.watchId)) AS numWatches,
  MAX(bids.bidPrice) AS highestBid, MAX(bids.bidPrice)as currentPrice,
  case
      when highestBidderId = bids.userId THEN true
      else false
  end as isUserWinning
  
  FROM auctions
  
  LEFT OUTER JOIN bids ON bids.auctionId = auctions.auctionId
  LEFT OUTER JOIN auction_watches ON auction_watches.auctionId = auctions.auctionId
  JOIN items ON items.itemId = auctions.itemId
  JOIN users ON items.userId = users.userId
  JOIN item_categories ON items.categoryId = item_categories.categoryId
  JOIN super_item_categories ON  item_categories.superCategoryId = super_item_categories.superCategoryId
  JOIN item_conditions ON items.conditionId = item_conditions.conditionId
  JOIN countries ON users.countryId = countries.countryId
  
  WHERE auctions.endTime &gt; now() AND auctions.auctionId IN ( SELECT bids.auctionId 
  FROM bids where bids.userId = bids.userId GROUP BY bids.auctionId)
  GROUP BY  auctions.auctionId,bids.userId
  ORDER BY endTime ASC";
  </code></pre>
  
  <p>Now, if I use this condition to determine the highest bidder, i am getting </p>
  
  <blockquote>
    <p>Outbidded, bid again to win! for all items.</p>
  </blockquote>
  
  <pre><code>if($row['endTime'] &gt;= $now){
      if($row['isUserWinning']){?&gt;
          &lt;p class="alert-success" style="padding: 7px 7px; border-radius: 3px;"&gt;Currently the highest bidder!&lt;/p&gt; &lt;?php
      }else{?&gt;
          &lt;p class="alert-warning" style="padding: 7px 7px; border-radius: 3px;"&gt;Outbidded, bid again to win!&lt;/p&gt; &lt;?php
      }
  }
  </code></pre>
  
  <p>What am I doing wrong or how can I go about it?</p>