我正在为客户建立一个拍卖网站,我有一个问题,我需要从投标表中删除投标,直到某一点,该点由投标人数或底价决定。
让我进一步解释。我有一张数据表:
Bidder1 $7,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $7,000.00 Sat 21 Jul 2012 12:26:34
Bidder1 $6,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $6,000.00 Sat 21 Jul 2012 12:26:11
Bidder1 $5,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $5,000.00 Sat 21 Jul 2012 12:25:34
Bidder2 $1,100.00 Sat 21 Jul 2012 12:23:53
Bidder1 $1,000.00 Sat 21 Jul 2012 12:22:33
Bidder1 $550.00 Sat 21 Jul 2012 12:22:33
Bidder2 $500.00 Sat 21 Jul 2012 12:22:23
Bidder2 $100.00 Sat 21 Jul 2012 12:22:23
正如您所看到的,有2个竞标者正在努力解决这个问题。现在每个投标人都可以随时取消他们的出价,但是,如果bidder2取消他们的出价,系统会将拍卖中的所有出价标记为已取消(客户要求),而不仅仅是他们的最新出价。如果是这种情况(bidder2取消他们的出价),那么bidder1的出价应该回滚到1000美元,这是拍卖的底价(因为你应该知道,因为bidder1连续有2个出价,550美元和1000美元)。
继续我所希望的只是棘手的一点而不是不可能的一点。假设我有3个投标人:
Bidder1 $7,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $7,000.00 Sat 21 Jul 2012 12:26:34
Bidder3 $6,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $6,000.00 Sat 21 Jul 2012 12:26:11
Bidder1 $5,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $5,000.00 Sat 21 Jul 2012 12:25:34
Bidder3 $1,100.00 Sat 21 Jul 2012 12:23:53
Bidder1 $1,000.00 Sat 21 Jul 2012 12:22:33
Bidder1 $550.00 Sat 21 Jul 2012 12:22:33
Bidder2 $500.00 Sat 21 Jul 2012 12:22:23
Bidder2 $100.00 Sat 21 Jul 2012 12:22:23
如果bidder2取消了他们的出价,那么我需要回滚到bidder3的最新出价,但仍然以bidder1获胜。
感谢任何指导。
答案 0 :(得分:1)
首先计算总数没有。投标人
$result = mysql_query("select distinct(bidder_id) from table where bid_id=1");
//考虑我们要删除bidder_id = 2个出价
if(mysql_num_rows($result) == 2 ) {
//select min bid of bidder
$row = mysql_fetch_row(mysql_query("select * from table where bidder_id=2 order by bid_price asc limit 1"));
$bidder_min_amount = $row['bid_price'];
$bidder_min_id = $row['id'];
//find out other bidder min bid id
/*
Bidder1 $7,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $7,000.00 Sat 21 Jul 2012 12:26:34
Bidder1 $6,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $6,000.00 Sat 21 Jul 2012 12:26:11
Bidder1 $5,250.00 Sat 21 Jul 2012 12:25:44
Bidder2 $5,000.00 Sat 21 Jul 2012 12:25:34
Bidder2 $1,100.00 Sat 21 Jul 2012 12:23:53
Bidder1 $1,000.00 Sat 21 Jul 2012 12:22:33
Bidder1 $550.00 Sat 21 Jul 2012 12:22:33
Bidder2 $500.00 Sat 21 Jul 2012 12:22:23
Bidder2 $100.00 Sat 21 Jul 2012 12:22:23
//may be first case like this
Bidder1 $75.00 Sat 21 Jul 2012 12:22:33
*/
//finding out if Bidder1 $75.00 exist
$row = mysql_query("select * from table where bid_price <= $bidder_min_amount and bidder_id!=2 order by bid_price asc");
if(mysql_num_rows($row) > 0 ) {
mysql_query("delete from table where id > ".$row['id'] );
} else {
$row = mysql_query("select * from table where bid_price >= $bidder_min_amount and bidder_id!=2 order by bid_price asc");
if(mysql_num_rows($row) > 0 ) {
mysql_query("delete from table where id > ".$row['id'] );
}
}
} //first condition complete if total bidder is 2
else {
//if n bidders just remove the bids of bidder
mysql_query("delete from table where bidder_id=2");
}
希望这会对你有所帮助。
答案 1 :(得分:0)
听起来你需要处理两种情况 - 首先是取消投标人是最高出价者;第二个是如果取消投标人不是最高出价者。
如果取消出价者是出价最高者,您可以在首次出价后删除每个出价,包括其他用户的出价。如果他们不是出价最高者,您只需删除所有出价并让其他用户独享。这是基于您提供的示例案例;如果这不正确,请告诉我,我会调整。
我假设您的数据库结构或多或少是这样的:
users
id
name
bids
id
user_id
auction_id
price
在运行删除之前,我会抓住当前拍卖的MAX(id)
以及取消竞价者对当前竞价的出价(假设竞价为#1,取消竞价者为#2):
SELECT MAX(id) AS max_auction FROM bids WHERE auction_id=1
SELECT MAX(id) AS max_bidder FROM bids WHERE auction_id=1 AND user_id=2
然后,您可以根据需要比较这两者和过程:
if ($max_auction == $max_bidder) {
// the cancelling-bidder is the highest-bidder
// get the ID of their first bid so we can delete every bid after it
$result = mysql_query("SELECT MIN(id) FROM bids WHERE auction_id=1 AND user_id=2");
$row = mysql_fetch_array($result);
mysql_query("DELETE FROM bids WHERE auction_id=1 AND id>=" . $row[0]);
} else {
// the cancelling-bidder is not the highest-bidder
// just remove all of their bids
mysql_query("DELETE FROM bids WHERE auction_id=1 AND user_id=2");
}
答案 2 :(得分:0)
对于两个以上的竞标者:
您有一个特殊情况,只有两个投标人:
这有点冗长 - 您不需要每次都进行分组 - 但我编写了它以便您可以在从db shell运行查询时确认结果。