techiefreak05 Posted December 11, 2008 Share Posted December 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/ Share on other sites More sharing options...
techiefreak05 Posted December 11, 2008 Author Share Posted December 11, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-712925 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-712952 Share on other sites More sharing options...
techiefreak05 Posted December 11, 2008 Author Share Posted December 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-712969 Share on other sites More sharing options...
techiefreak05 Posted December 11, 2008 Author Share Posted December 11, 2008 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?? Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-712998 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-713011 Share on other sites More sharing options...
techiefreak05 Posted December 11, 2008 Author Share Posted December 11, 2008 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()); } } Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-713030 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 yeah, man with most money wins. query the bidders, order them by max bid so that the highest bid is the first entry u get. input their name or id in as the winning person. lame, simple, but honest. lol Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-713036 Share on other sites More sharing options...
techiefreak05 Posted December 11, 2008 Author Share Posted December 11, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-713042 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 that's why you make a check before auto bidding that their new bid will be less than or equal to their max. if it is higher than max, then don't auto bid. Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-713055 Share on other sites More sharing options...
techiefreak05 Posted December 11, 2008 Author Share Posted December 11, 2008 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()); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/136519-solved-complex-max-bid-feature-for-auction-script/#findComment-713075 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.