0

我有一个 MySQL 表,其中包含以下列

urlByCustomer table
----------------------------------------------
|customerID | TeamID | date | numUrlsConsumed|
----------------------------------------------
|           |        |      |                | 
----------------------------------------------

urlmapping

Column  Type    Null    Default Comments    MIME
urlMappingID    bigint(20)  No           
customerID  int(11) Yes     0        
activityID  int(11) Yes     0        
contactID   int(11) Yes     0        
fullURL mediumtext  Yes     NULL         
lastModified    timestamp   No  CURRENT_TIMESTAMP        
developerSandbox    varchar(25) Yes              

我有正在执行的代码来更新表

 $start = strtotime(date('Y-m-d 00:00:00'));
                             $end = strtotime(date('Y-m-d 23:59:59'));
                             $countAllThisGuysVals = "SELECT COUNT( DISTINCT`customerID`,`fullURL`)  
                                                      FROM `urlmapping` 
                                                      WHERE `urlMappingID` >= $ORIGINAL_COPY 
                                                      AND `customerID` = $currentCustomerID";
                            $countTheVals= $conn->query($countAllThisGuysVals);
                            $countedfinal =0;
                            foreach ($countTheVals as $countRow) {
                                $countedfinal = array_sum($countRow)/2;
                            }
                                $tableUpdateQuery = "UPDATE `urlByCustomer`
                                                SET `date` = NOW()
                                                WHERE `customerID`= $currentCustomerID AND 
                                                      UNIX_TIMESTAMP(`date`) BETWEEN '{$start}' and '{$end}'";

                                $conn->exec($tableUpdateQuery);

                                 $tableUpdateQuery = "UPDATE `urlByCustomer`
                                                SET `numUrlsConsumed` = $countedfinal
                                                WHERE `customerID`= $currentCustomerID AND 
                                                      UNIX_TIMESTAMP(`date`) BETWEEN '{$start}' and '{$end}'";
                                $conn->exec($tableUpdateQuery);
                                echo "update path <br>";
                                $tableModified = true;
                                $originalLPID++;

变量几乎都被声明了,但是声明被分散了,所以我只是发布这部分来缩短它。对日期列的更新查询似乎有效,但第二次更新无效。虽然它在 17 分钟前工作,所以我很困惑,因为在下一次测试之间唯一改变的是我添加了一些新值,这些值应该会导致它更新该列。

同上。我想一种可能性可能是 UNIX_TIMESTAMP。我在 Mac 上的 Parallels 中运行它,所以我不确定时间戳的含义。

4

1 回答 1

0

看起来您在第一次更新中更改了“日期”的值,而没有考虑到您的第二次更新现在不会在 WHERE 子句中找到相同的行(因为您刚刚更改了日期)。

您可以在单个语句中进行更新::

UPDATE urlByCustomer
SET `date` = NOW()
, numUrlsConsumed = $countedfinal
WHERE customerID= $currentCustomerID 
AND UNIX_TIMESTAMP(`date`) BETWEEN '{$start}' and '{$end}'
于 2012-07-18T07:10:59.553 回答