I have multiple rows with data, some with data in mysql table kjoring
and some that don't.
I am able to echo
both $km1
and $km2
correctly, but I am unable to subtract them to find the result and echo $km0
$sqlq = "SELECT kjoring FROM oko WHERE kjoring!='' ORDER BY logdate DESC LIMIT 2";
if ( array_key_exists( 'field' , $out ) ) {
$sqlq = $sqlq . " where field = '" . $out['field'] . "'" ;
}
$conn = new mysqli($servername, $username, $password, $dbname);
$result = mysqli_query( $conn , $sqlq );
if ( $result->num_rows > 0 ) {
while($row = mysqli_fetch_array($result)) {
$km1 = $row[0];
$km2 = $row[1];
$km0 = $km1 - $km2 ;
}
}
echo $km0 ;