我有两个来自 sql 的计数查询。我想划分这两个查询的结果。我试过了:
$con = mysqli_connect("localhost", "root", "", "xoxo") or die(mysqli_connect_error());
$query = "SELECT COUNT(xxxx) AS a zzzz";
$query1 = "SELECT COUNT(xxxx) AS b FROM zzzz WHERE xxxx = 'cccc'";
$result = mysqli_query($con, $query) or die('Error querying database');
$result1 = mysqli_query($con, $query1) or die('Error querying database');
$row = mysqli_fetch_array($result);
$rowa = mysqli_fetch_array($result1);
$x = $row/$rowa;
echo $x;
但它告诉我它有一个致命的错误。我也试过:
$con = mysqli_connect("localhost", "root", "", "xoxo") 或 die(mysqli_connect_error());
$query = "SELECT COUNT(xxxx) AS row1 FROM zzzz";
$query1 = "SELECT COUNT(xxxx) AS row2 FROM zzzz WHERE xxxx = 'cccc'";
$result = mysqli_query($con, $query) or die('Error querying database');
$result1 = mysqli_query($con, $query1) or die('Error querying database');
while ($row = mysqli_fetch_array($result)) {
}
while ($row1 = mysqli_fetch_array($result1)) {
}
echo (int)($row['row1'] / $row1['row2']);
但它告诉我这是除以零。但是,我的 row1 和 row2 都对它有价值。