你能建议我如何在选择Mysql中返回计数行数吗?
$n_quakes = "SELECT COUNT(*)
FROM earthquakes
WHERE milliseconds >= 1000
AND milliseconds <= 2000
AND magnitude >= 4
AND magnitude <= 8
AND ipocentro >= 50
AND ipocentro <= 800
AND latitude >= 40
AND latitude <= 50
AND longitude >= 30
AND longitude <= 70";
这样我会知道行数吗?
在我的代码中不起作用,但如果这是错误或在代码的其他地方,我不会这样做。
感谢您的帮助,对不起我的英语
答案 0 :(得分:2)
在
之间尝试$count = mysqli_fetch_array(mysqli_query($coni, "SELECT COUNT(*) as totalCount
FROM earthquakes
WHERE (milliseconds between 1000 and 2000) and (magnitude between 4 and 8) AND (ipocentro between 50 and 800) AND (latitude between 40 and 50) and (longitude between 30 and 70)"));
$actualCount = $count['totalCount'];
答案 1 :(得分:0)
尝试此代码,其中mysqli_num_rows返回行数,$ con是数据库连接变量
$n_quakes = mysqli_num_rows(mysqli_query($con, "SELECT id FROM earthquakes WHERE milliseconds >= 1000 AND milliseconds <= 2000 AND magnitude >= 4 AND magnitude <= 8 AND ipocentro >= 50 AND ipocentro <= 800 AND latitude >= 40 AND latitude <= 50 AND longitude >= 30 AND longitude <= 70"));