--- a/admin/linkAmendments.php +++ b/admin/linkAmendments.php @@ -1,15 +1,23 @@ 0 "; -$result = mysql_query($query); -while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { - $result2 = mysql_query("UPDATE contractnotice SET childCN = '" . - $row['CNID'] . "', amendmentReason = '" . - $row['amendmentReason'] . "' where CNID = '" . - $row['parentCN'] . "';"); - if ($result2) echo $row['CNID'] . " linked to parent " . $row['parentCN'] . +$query = 'SELECT "CNID","parentCN","amendmentReason" FROM contractnotice WHERE +"parentCN" > 0 '; +$query = $conn->prepare($query); + $query->execute(); + if (!$query) { + databaseError($conn->errorInfo()); + } +foreach ($query->fetchAll() as $row) { + $conn->exec('UPDATE contractnotice SET childCN = "' . + $row['CNID'] . '", amendmentReason = "' . + $row['amendmentReason'] . '" where "CNID" = "' . + $row['parentCN'] . '";'); + $errors = $conn->errorInfo(); + + if ($errors[1] == 7 || $errors[1] ==0) + echo $row['CNID'] . " linked to parent " . $row['parentCN'] . "
\n"; - else "error" . mysql_error(); + else print_r($errors); + } ?>