I have written two different codes in php and I want to merge it with only one code because both codes are the same, only UPDATE
Query is different. Can any one help me? and the second problem is if
Condition does'nt work why is that?
code1:
<?php
include("Database/connection.php");
$sql = "SELECT * FROM registration,billing_month";
$result = $link->query($sql);
while ($row = $result->fetch_assoc()) {
$regid = $row['Reg_id'];
$duedate = $row['Bill_due_date'];
$currentbill = $row['Current_Bill'];
$arrears = $row['Arrears'];
$updatearrears = $arrears + $currentbill;
if (date('Y-m-d') > $duedate) {
$sql_update = "UPDATE registration SET Arrears= $updatearrears WHERE Reg_id = $regid";
if (mysqli_query($link, $sql_update)) {
// echo "Updated";
} else {
// echo "Could not updated";
}
}
}
?>
Code2:
<?php
include("Database/connection.php");
$sql = "SELECT * FROM registration,billing_month";
$result = $link->query($sql);
while ($row = $result->fetch_assoc()) {
$regid = $row['Reg_id'];
$billingid = $row['Bill_id'];
$duedate = $row['Bill_due_date'];
$currentbill = $row['Current_Bill'];
$updatebill = 0;
if (date('Y-m-d') > $duedate) {
$sql_update = "UPDATE registration SET Current_Bill= $updatebill WHERE Reg_id = $regid";
if (mysqli_query($link, $sql_update)) {
// echo "Updated";
} else {
// echo "Could not updated";
}
}
}
?>