简体   繁体   English

通过在列中插入相同的值来“插入SQL”

[英]“Insert SQL” by inserting the same value into the column

I have a bidding system that works with a robotic bidding automatic, and also with a button where the customer can bid. 我有一个出价系统,可以与自动出价系统配合使用,还可以与客户可以出价的按钮一起使用。

When the client clicks the button, it calls a function that executes the following query: 客户端单击该按钮时,它将调用一个函数,该函数执行以下查询:

$qryins = "Insert into bid_account (user_id,bidpack_buy_date,bid_count,auction_id,product_id,bid_flag,bidding_price,bidding_type,bidding_time)
                values('$uid',NOW(),'1','$aid','$prid','d',$newprice,'s'," . $oldtime . ")";

This query is in a PHP file. 该查询在PHP文件中。

The part of robotic is done by a procedure in the database, with the following command, which runs every second: 机械手的一部分由数据库中的过程完成,并使用以下命令,该命令每秒运行一次:

Insert into bid_account (user_id, bidpack_buy_date, bid_count, auction_id, product_id, bid_flag, bidding_price, bidding_type, bidding_time)
        SELECT prox_user_id, NOW(), '1', auctionID, productID, 'd', prox_valor, 's', auc_due_time FROM t_autolances
        WHERE prox_valor NOT IN (SELECT bidding_price FROM bid_account WHERE auction_id=auctionID); 

Bids are run with a timer, equal to those auctions of cents. 竞标有一个计时器,等于这些美分的拍卖。 The problem that is occurring is that if the customer clicks the button at the same time that the robo gives the bid, it writes to the database with equal values. 出现的问题是,如果客户在机器人给出出价的同时单击按钮,它将以相等的值写入数据库。

I need it to write the different value to the " bidding_price " column, like this: 我需要它将不同的值写入“ bidding_price ”列,如下所示:

I need it written this way: 我需要这样写:

robot 0.25
customer 0.26

and not like this: 而不是这样:

robot 0.25
client 0.25

I did not want to put all the code here because it is too long, so I put the most important parts. 我不想将所有代码都放在这里,因为它太长了,所以我将最重要的部分放在这里。

$q = "select * from auc_due_table adt left join auction a on adt.auction_id=a.auctionID left join auction_management am on a.time_duration=am.auc_manage where auction_id=$aid";
$r = mysqli_query($db, $q);
$ob = mysqli_fetch_object($r);

$oldtime = $ob->auc_due_time;
$oldprice = $ob->auc_due_price;
$plusprice = $ob->auc_plus_price;
$plustime = $ob->auc_plus_time;
$newprice = $ob->pennyauction == 1 ? $oldprice + 0.01 : $oldprice + $plusprice;
$newtime = $oldtime < $plustime ? $plustime : $oldtime;

maybe this: 也许这:

   Insert 
       into bid_account 
                     (
                     user_id, 
                     bidpack_buy_date, 
                     bid_count, 
                     auction_id, 
                     product_id, 
                     bid_flag, 
                     bidding_price, 
                     bidding_type, 
                     bidding_time
                     )
             SELECT 
                     prox_user_id, 
                     NOW(), 
                     '1', 
                     auctionID, 
                     productID, 
                     'd', 
                     (SELECT max(bidding_price)+0.01 FROM bid_account WHERE auction_id=auctionID) AS bidding_price,                     
                     's', 
                     auc_due_time 
             FROM 
                     t_autolances
             LIMIT 1

You need to do the addition of the user's amount in SQL, not in PHP. 您需要在SQL中而不是在PHP中添加用户数量。

$qryins = "Insert into bid_account (user_id,bidpack_buy_date,bid_count,auction_id,product_id,bid_flag,bidding_price,bidding_type,bidding_time)
            SELECT '$uid', NOW(),'1', auction_id, '$prid','d', 
                    auc_due_price + IF(pennyauction, 0.01, auc_plus_price), 's', auc_due_time
            from auc_due_table adt 
            left join auction a on adt.auction_id=a.auctionID 
            left join auction_management am on a.time_duration=am.auc_manage 
            where auction_id=$aid";

The other solution is to use a transaction. 另一种解决方案是使用事务。 Start the transaction before the SELECT query, and commit it after the INSERT . SELECT查询之前启动事务,并在INSERT之后提交事务。

mysqli_query($db, "START TRANSACTION");
$r = mysqli_query($db, $q);
$ob = mysqli_fetch_object($r);
$oldtime = $ob->auc_due_time;
$oldprice = $ob->auc_due_price;
$plusprice = $ob->auc_plus_price;
$plustime = $ob->auc_plus_time;
$newprice = $ob->pennyauction == 1 ? $oldprice + 0.01 : $oldprice + $plusprice;
$newtime = $oldtime < $plustime ? $plustime : $oldtime;
$qryins = "...";
mysqli_query($db, $qryins);
mysqli_query($db, "COMMIT");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM