--- a/admin/linkAmendments.php +++ b/admin/linkAmendments.php @@ -1,6 +1,6 @@ 0 AND p."childCN" IS NULL '; $query = $conn->prepare($query); @@ -10,12 +10,10 @@ } foreach ($query->fetchAll() as $row) { $conn->exec('UPDATE contractnotice SET "childCN" = \'' . - $row['CNID'] . '\', "amendmentReason" = \'' . - $row['amendmentReason'] . '\' where "CNID" = \'' . + $row['CNID'] . '\' where "CNID" = \'' . $row['parentCN'] . '\';'); - //echo 'UPDATE contractnotice SET "childCN" = \'' . - $row['CNID'] . '\', "amendmentReason" = \'' . - $row['amendmentReason'] . '\' where "CNID" = \'' . +echo 'UPDATE contractnotice SET "childCN" = \'' . + $row['CNID'] . '\' where "CNID" = \'' . $row['parentCN'] . '\';'; $errors = $conn->errorInfo(); @@ -36,5 +34,26 @@ ) AND "childCN" = 0 GROUP BY "parentCN" having count(*) > 1'; +$query = $conn->prepare($query); + $query->execute(); + if (!$query) { + databaseError($conn->errorInfo()); + } +foreach ($query->fetchAll() as $row) { + $cnids = explode(",",str_replace(Array("{","}"),"",$row['array_agg'])); + $last_cnid = array_pop($cnids); + foreach ($cnids as $cnid) { + $conn->exec('UPDATE contractnotice SET "childCN" = \'' . + $last_cnid . '\' where "CNID" = \'' . + $cnid . '\';'); + + $errors = $conn->errorInfo(); + + if ($errors[1] == 7 || $errors[1] ==0) + echo $cnid . " linked to latest child " . $last_cnid . + "
\n"; + else print_r($errors); +} +} ?>