我搜索了效果很好的城市:
$sql = "`status`,`name`,`zip`,`city`, `xxx`, `yyy`";
$geo = "(".$radius." * SQRT(2*(1-cos(RADIANS(breit)) *
cos(".$rad_b.") * (sin(RADIANS(lang)) *
sin(".$rad_l.") + cos(RADIANS(lang)) *
cos(".$rad_l.")) - sin(RADIANS(breit)) *
sin(".$rad_b."))))";
$select = "SELECT $sql, $geo AS distance FROM TABLE Having
((distance <= '".$area."') or (distance <= 20 && `city` = '".$city."')) &&
`status` BETWEEN '1' AND '10'
ORDER BY `city` = '".$city."' DESC, distance, RAND()";
$result = mysqli_query($db,$select);
现在我要计算有多少xxx字段的值为1。 有没有人有解决方案?
谢谢JK
答案 0 :(得分:0)
你可以使用
SELECT COUNT(1) FROM table WHERE value = 1
$select1 = "SELECT COUNT(1) FROM table WHERE xxx = 1 HAVING
((distance <= '".$area."') OR (distance <= 20 && `city` = '".$city."'))
ORDER BY `city` = '".$city."' DESC, distance, RAND()";
$result1 = mysqli_query($db,$select1);
这样你就可以在$ result1变量中得到你的值
SELECT $ sql,$ geo AS FROM FROM TABLE
((距离&lt; ='“。$ area。”')或(距离&lt; = 20&amp;&amp; city
='“。$ city。”'))&amp;&amp;
'{1}}在'1'和'10'之间
ORDER BY status
='“。$ city。”'DESC,距离,兰德()