www.fusebox.org



Navigation:


FORUMS > Code Warriors < refresh >
Topic Title: Auction Software - Current Bid
Created On Thu October 06, 2005 2:48 PM
Topic View:

View thread in raw text format


ibjhb
Member

Posts: 49
Joined: Nov 2002

Thu October 06, 2005 2:48 PM
User is offline

I'm trying to figure out the logic on how to calculate a high bidder
for auction software.


I have a table (Bids) with these columns:


BidID
ContactID
BidAmount
AuctionID


I'm not sure how to loop through and calculate the bid.


The conditions I have are:


1) There's a minimum bid on the auction (assume $50)
2) The next bid has to be 10% higher than the current bid.
3) People can put a max bid in and the system will bid up for you (like
eBay does).
4) When someone has a max bid in higher than the 10% of the current bid
(think previous bid), the new current bid is 10% higher than the
previous bid.
5) If two people bid the same amount, the previous bid (time-wise) is
the high bidder.


My first thought was to calculate the whole thing on the fly and here
is what I came up with:


<cfset iCount = 0>
<cfset bids.CurrentBid = 0>
<cfset HighBidFound = False>


<cfquery name="getHighBids" datasource="#request.maindsn#">
SELECT BidID, AuctionID, BidAmount, ContactID
FROM Bids
WHERE
Bids.AuctionID = <cfqueryparam value="#attributes.AuctionID#"
cfsqltype="cf_sql_varchar">
ORDER BY BidAmount, BidID ASC
</cfquery>


<cfif getHighBids.RecordCount EQ 0>
<cfset theActualCurrentBid = getAuctions.MinimumBid>
<cfset theActualNext = getAuctions.MinimumBid>
<cfset theHighBidder = 0>
<cfexit>
<cfelseif getHighBids.RecordCount EQ 1>
<cfset theActualCurrentBid = getHighBids.BidAmount>
<cfset theActualNext = getHighBids.BidAmount * 1.1>
<cfset theHighBidder = getHighBids.ContactID>
<cfexit>
</cfif>


<cfset getBids = StructNew()>
<cfoutput query="getHighBids">
<cfset getbids.BidAmount[currentrow] = getHighBids.BidAmount>
<cfset getBids.BidderID[currentrow] = getHighBids.ContactID>
</cfoutput>


<cfset a.CurrentBid = getbids.BidAmount[1]>
<cfset a.NextBid = getbids.BidAmount[1] * 1.1>
<cfset a.CurrentHigh = getBids.BidderID[1]>


<cfoutput>
<cfloop index="iCount" from="#StructCount(getBids.BidAmount)#" to="1"
step="-1">
<cfset CurrentBidder = getBids.BidderID[iCount]>


<cfif iCount-1 EQ 0>
<cfbreak>
</cfif>


<cfif CurrentBidder EQ getBids.BidderID[iCount-1]>
<cfelse>
<cfset a.CurrentBid = getbids.BidAmount[iCount-1]>
<cfset a.NextBid = getbids.BidAmount[iCount-1] * 1.1>


<cfif getBids.BidAmount[StructCount(getBids.BidAmount)-1] EQ
getBids.BidAmount[StructCount(getBids.BidAmount)]>
<cfset a.CurrentHigh = getBids.BidderID[iCount-1]>
<cfelse>
<cfset a.CurrentHigh = getBids.BidderID[iCount]>
</cfif>


<cfbreak>
</cfif>


</cfloop>
</cfoutput>


<cfset theActualCurrentBid = a.CurrentBid>
<cfset theActualNext = a.NextBid>
<cfset theHighBidder = a.CurrentHigh>


This doesn't quite work right and I'm wondering if I need to calculate
and store each "current bid" in a database.


I've been working on this problem for a while so if anybody could help
me, I'd appreciate it.
 
Reply
   
Quote
   
Top
   
Bottom
     



barneyb
Senior Member

Posts: 413
Joined: Nov 2002

Thu October 06, 2005 4:49 PM
User is offline View users profile

I can't say for sure, but I'm thinking that if you could track current price in one table, and then have another table for all the bids (both actual and max). Each time a bid comes in, you scan the table for the earliest bidder that has a max bid of at least 110% of the new bid, and automatially add a bid on his behalf. That, of course, starts the process over again, since a new bid was made.

SELECT TOP 1
FROM bids
WHERE maxBid >= #1.10 * latestBid#
ORDER BY createDate

If that returns a record, bid on that bidder's behalf, and repeat.

-------------------------
barneyb
bboisvert@gmail.com
http://www.barneyb.com/
Got GMail? I have 198 invites.
 
Reply
   
Quote
   
Top
   
Bottom
     



ibjhb
Member

Posts: 49
Joined: Nov 2002

Thu October 06, 2005 8:02 PM
User is offline

I thought about that and was going to try to go that route... It just gets complicated when people bid say $1000 higher than their current bid and someone comes and bids like $250... the system has to figure the proxy bid.

I'll try that and see. Thanks!
 
Reply
   
Quote
   
Top
   
Bottom
     

View thread in raw text format
FORUMS > Code Warriors < refresh >

Navigation:

FuseTalk 4.0 © 1999-2003 FuseTalk Inc.