Reputation: 179
i am making a web app and i need to get two variables convert then subtract them from each other to get the elapsed time here is what i currently have.
public function Cycle() {
$conn = odbc_connect('monitor', '', '');
if (!$conn) {
exit("Connection Failed: " . $conn);
}
$sql = " SELECT TOP 2 ReaderData.ReaderIndex, ReaderData.CardID, ReaderData.ReaderDate, ReaderData.ReaderTime, ReaderData.controllerID, Left([dtReading],10) AS [date], ReaderData.dtReading FROM ReaderData WHERE ReaderData.controllerID=$this->Id ORDER BY ReaderData.ReaderIndex desc;";
$rs = odbc_exec($conn, $sql);
if (!$rs) {
exit("Error in SQL");
}
while (odbc_fetch_row($rs)) {
$this->DtReading = odbc_result($rs, "dtReading");
echo $this->DtReading." ";
}
odbc_close($conn);
}
currently this Outputs the two rows that i need, so what would be the best way to take the variable DtReading from each row and store them in separate variables so i can do things with them?
Thanks
Upvotes: 1
Views: 72
Reputation: 20469
Save the values into an array:
$data=array();
while (odbc_fetch_row($rs)) {
$data[] = $this->DtReading = odbc_result($rs, "dtReading");
}
$result = $data[0] - $data[1];
Upvotes: 3