Jump to content

Recommended Posts

Hi,

I was hired by my uncle to write an auction script.. everything is okay so far, seeing as I've never attempted this kind of site before, until he said he wanted users to be able to set a max bid, and once their original bid was outbid, then it would kick in and keep increasing their bid in $50 increments until it hit their max. I've been having an issue just getting my head around the concept, leading to much frustration and confusion.

 

Here is the database setup:

 

tbl_auction: holds the current winner, and their bid, for the time being.

--AuctionID: auto-increment

--DealerCarID: id of the car that the auction is attached to.

--CurWinBid: the current winning BID amount

--CurWinBidID: ID of the current WINNER.

 

tbl_auctiondetail: bad name, should be named tbl_bids. it holds the bid info.

--DealerCarId: same as above

--BidderId: bidder's UserID ($_SESSION['id'])

--BidderPrice: The original bid amount of the bidder

--BidderDate: time() value that bid was either placed/updated.

--BidderMax: max amount system should auto-bid until.

 

My uncle's brother created the database setup, I did not. They basically said I cannot change it.

 

I have the bidding working, where you have to bid at least $50 over what the current winning bid is, and it keeps increasing, but you have to manually bid.

 

Here's is how I handle the bidding... I know there are some security issues which i will fix after I get this working.

 

**************************

<?php
///////////////////////WHEN BID IS PLACED////////////////////////
if($_POST['doBid']){

	$testRow="SELECT * FROM `tbl_auction` WHERE `DealerCarID` = '" . $_GET['id'] . "'";
	$testQ=mysql_query($testRow) or die(mysql_error());

	if(mysql_num_rows($testQ)<1){ //if user is first bidder.
		mysql_query("
			INSERT INTO `tbl_auction` (
`DealerCarID` ,
`AStatus` ,
`WinStatus` ,
`CurWinBidID` ,
`CurWinBid`
)
VALUES (
'" . $_GET['id'] . "',  '',  '',  '" . $_SESSION['id'] . "',  '" . $_POST['next'] . "'
);
			") or die(mysql_error());
	}

	mysql_query("UPDATE `tbl_auction` SET `CurWinBid` = '" . $_POST['next'] . "', `CurWinBidID` = '" . $_SESSION['id'] . "' WHERE DealerCarID = '$CarID'") or die(mysql_error());
	$sql4="SELECT `BidderMax` FROM `tbl_auctiondetail` WHERE `DealerCarId` = '$CarID' AND `BidderId` = '" . $_SESSION['id'] . "'";
	$query4=mysql_query($sql4) or die(mysql_error());

	if(mysql_num_rows($query4)<1){ // if user has not bid before, insert their bid.
		mysql_query("
			INSERT INTO `tbl_auctiondetail` (
`DealerCarId` ,
`BidderId` ,
`BidderPrice` ,
`BidderDate` ,
`BidderMax`
)
VALUES (
'" . $_GET['id'] . "',  '" . $_SESSION['id'] . "',  '" . $_POST['next'] . "',  '" . time() . "',  '" . $_POST['max'] . "'
);
") or die(mysql_error());

	}else{ // OTHERWISE, update their bid.

	mysql_query("UPDATE `tbl_auctiondetail` SET `BidderPrice` = '" . $_POST['next'] . "', `BidderDate` = '" . time() . "', `BidderMax` = '" . $_POST['max'] . "' WHERE `DealerCarId` = '$CarID' AND `BidderId` = '" . $_SESSION['id'] . "'") or die(mysql_error());	

	}

header("location: /auctionView.php?id=" . $_GET['id']);
exit;
}
?>

**************************

 

I'd appreciate any help in the right direction. The code is insanely crazy because I'm running my head in circles, as he's getting impatient.

 

Thanks.

Some more info,

 

$_POST['next'] is the original bid you place.

$_POST['max'] is your max bid.

in the 'tbl_auctiondetail' table, 'DealerCarId' comes from $_GET['id']

Each auction has 1 row in the 'tbl_auction' table, while the 'tbl_auctiondetails' holds all the bids, each user places 1 bid, and can then update it.

 

Here's ultimately what I'm looking for:

 

When someone pushes "BID" ($_POST['doBid'])

if you bid higher than someone else, their max bid will outbid you (by $50)

and if someone outbids you, your max bid will outbid them (by $50)

 

run a loop for each bidder when the new bid is placed {

if their bid < the posted bid && their bid + 100 <= their max bid {

    UPDATE with their bid plus $100

    }

}

 

that might work as what your looking for.

 

by "their bid" you mean the bid they palced? and "the posted bid" you mean the current high bid?

 

I'll try it

I have this and I think I almost got it, The first bidder set his max at 75,000 where bidding started at 60,000, and when the 2nd bidder bid, he was outbid, meaning the first bidder's Max bid kicked in (thats good!) except once we went past the first bidders max, he was still winning....

<?php
	$testRow2="SELECT * FROM `tbl_auctiondetail` WHERE `DealerCarId` = '" . $_GET['id'] . "'";
	$testQ2=mysql_query($testRow2) or die(mysql_error());
	while($r=mysql_fetch_assoc($testQ2)){
		if( ($winnerBid < $_POST['next']) && ($winnerBid+50 <= $r['BidderMax']) ){
			$newBid=$_POST['next']+50;
			mysql_query("UPDATE `tbl_auction` SET `CurWinBid` = '" . $newBid . "', `CurWinBidID` = '" . $r['BidderId'] . "' WHERE DealerCarID = '$CarID'") or die(mysql_error());
		}
	}
?>

 

$winnerBid is the current high-bid.

 

Is my logic off??

 

 

posted bid is the bid the person is making and "their bid" is the bid of the user that is being looked at for that limit.

you want to query and get all the the bids for that item

run a loop for each bidder when the new bid is placed {

in the loop, check to see if that particular bid is less than ( < ) the bid the person that executed the page *who is the latest bidder*. If it is less than that bid and also their bid +100 is still less than their max bid, UPDATE their bid to $50 more than the bid being posted right NOW.

 

than do it again and again for each bidder

 

their is no person winning till there is only one bidder that hasn't hit their max. so, in that for each statement, make an incrimenting value starting at 0 and getting +1 every time the bid is raised for someone and also their id that is replaced every time that a bid is bumped up. if when the loop is done the number is == 1, then that person that the other variable has stored their id is the winner.

 

Get it?

Beofer I read that reply, I came up with this.. it almost works in the sense that the person who has the highest Max will be winning, but if the bid gets OVER the max bid, the person is still winning..

 

as long as they have the highest max bid, they are winning, even if it goes passed their max, they will still be winning.

 

I'm assuming its something in my IF's

	$testRow2="SELECT * FROM `tbl_auctiondetail` WHERE `DealerCarId` = '" . $_GET['id'] . "'";
	$testQ2=mysql_query($testRow2) or die(mysql_error());
	while($r=mysql_fetch_assoc($testQ2)){
		if( ($r['BidderMax'] > $_POST['max']) && ($winnerBid+50 <= $r['BidderMax']) ){
			$newBid=$_POST['next']+50;
			mysql_query("UPDATE `tbl_auction` SET `CurWinBid` = '" . $newBid . "', `CurWinBidID` = '" . $r['BidderId'] . "' WHERE DealerCarID = '$CarID'") or die(mysql_error());
		}else if($r['BidderMax'] <= $_POST['max']){
			mysql_query("UPDATE `tbl_auction` SET `CurWinBid` = '" . $_POST['next'] . "', `CurWinBidID` = '" . $_SESSION['id'] . "' WHERE DealerCarID = '$CarID'") or die(mysql_error());
		}
	}

 

 

Yeah the person with highest max, wins, but if the person who has a small max, MAUNALLY bids higher than the winners max, the winner.. is still winning, and the system keeps bidding for them even PAST their max... which could be bad..

Duh thanks.

 

THIS WORKS:

<?php

	$testRow2="SELECT * FROM `tbl_auctiondetail` WHERE `DealerCarId` = '" . $_GET['id'] . "'";
	$testQ2=mysql_query($testRow2) or die(mysql_error());
	while($r=mysql_fetch_assoc($testQ2)){
	$newBid=$_POST['next']+50;
		if($r['BidderMax'] > $_POST['max']){
			if( ($r['BidderMax'] >= $winnerBid) && ($newBid <= $r['BidderMax']) ){				
				mysql_query("UPDATE `tbl_auction` SET `CurWinBid` = '" . $newBid . "', `CurWinBidID` = '" . $r['BidderId'] . "' WHERE DealerCarID = '$CarID'") or die(mysql_error());
			}else{
				mysql_query("UPDATE `tbl_auction` SET `CurWinBid` = '" . $_POST['next'] . "', `CurWinBidID` = '" . $_SESSION['id'] . "' WHERE DealerCarID = '$CarID'") or die(mysql_error());
			}
		}else if($r['BidderMax'] <= $_POST['max']){
			mysql_query("UPDATE `tbl_auction` SET `CurWinBid` = '" . $_POST['next'] . "', `CurWinBidID` = '" . $_SESSION['id'] . "' WHERE DealerCarID = '$CarID'") or die(mysql_error());
		}
	}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.