我正在尝试显示一个结果,该结果将显示在给定时间跨度内支付的所有租金的总和。但是我收到了错误"可恢复的致命错误:类mysqli_result的对象无法转换为字符串"
有没有办法可以使用PHP显示这些数据?
以下是我的代码:
<?php
ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$dateto = filter_input(INPUT_POST, 'dateto');
$datefrom = filter_input(INPUT_POST, 'datefrom');
if(!empty($dateto)){
if(!empty($datefrom)){
$host = "";
$dbusername = "";
$dbpassword = "";
$dbname = "some_db";
//new connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
if(mysqli_connect_error()){
die('Connect Error ('. mysqli_connect_errno().')'
. mysqli_connect_error());
}
else{
$sql = "SELECT SUM(rentpm) FROM tenants";
$result = $conn->query($sql);
if ($conn->query($sql)){
echo $result;
}
else{
echo "Error: " . $sql ."<br>".$conn->error;
}
$conn->close();
}
}
else{
echo "All fields are required!";
die();
}
}
else{
echo "Please fill out all fields to continue.";
die();
}
?>