Hi Gurus,
please help me on my small php project, I want to place the result of a date calculation inside a Query statement into the table, but it seems that the php cannot recognize the index (“next_cal”) from the Query.
<?php
try {
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT calrecord.cal_id, equipment.mach_no, equipment.brand, equipment.description, calrecord.employeenumber, equipment.cal_interval, calrecord.cal_date, calrecord.next_cal = DATE_ADD(calrecord.cal_date, INTERVAL equipment.cal_interval DAY)
from calrecord
INNER JOIN equipment ON calrecord.equip_id = equipment.equip_id Order By cal_date DESC";
$statement = $connection->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
?>
<h2>Calibration Record</h2>
<table>
<thead>
<tr>
<th>Calibration ID</th>
<th>Machine/Equipment No.</th>
<th>Brand</th>
<th>Description</th>
<th>Employee Number</th>
<th>Calibration Interval</th>
<th>Calibration Date</th>
<th>Next Calibration</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
foreach ($result as $row) : ?>
<tr>
<td><?php echo escape($row["cal_id"]); ?></td>
<td><?php echo escape($row["mach_no"]); ?></td>
<td><?php echo escape($row["brand"]); ?></td>
<td><?php echo escape($row["description"]); ?></td>
<td><?php echo escape($row["employeenumber"]); ?></td>
<td><?php echo escape($row["cal_interval"]); ?></td>
<td><?php echo escape($row["cal_date"]); ?> </td>
<td><?php echo escape($row["next_cal"]); ?> </td>
<td><a href="update-single-calrec.php?id=<?php echo escape($row["cal_id"]); ?>">Edit</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="index.php">Back to home</a>
<?php require "templates/footer.php"; ?>