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++;

変数はほとんどすべて宣言されていますが、宣言は分散しているので、この部分を投稿して短縮します。日付列への更新クエリは機能しているようですが、2番目の更新は機能していません。17分前は機能していましたが、次のテストで変更されたのは、その列を更新するための新しい値を追加したことだけだったので、混乱しました。

Idk。1つの可能性はUNIX_TIMESTAMPである可能性があると思います。私はこれをMacのParallelsで実行しているので、タイムスタンプに何が変換されるのかわかりません。

4

1 に答える 1

0

2番目の更新でWHERE句に同じ行が見つからないという事実を考慮せずに、最初の更新で「date」の値を変更しているようです(日付を変更したばかりです)。

1つのステートメントで更新を実行できます::

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