MySQLi中的计数[重复项]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQLi中的计数[重复项]相关的知识,希望对你有一定的参考价值。
此问题已经在这里有了答案:
我有一个复杂的mysqli_query,它显示结果,但不计算在内。我应该两次运行相同的脚本?或其他建议?
$ sql应该给我结果,而$ count应该计算完全相同的条件。 $ count用于分页
我尝试了不同类型的计数,但仍然告诉我mysqli_fetch_array会获得布尔值而不是查询。
我有2个脚本,非常相似:
$sql = "(SELECT account_id FROM work
WHERE
(company LIKE '%".$includewords."%'
OR function LIKE '%".$includewords."%'
OR duties LIKE '%".$includewords."%'
OR achievements LIKE '%".$includewords."%'
OR reason_for_leaving LIKE '%".$includewords."%')
AND
(company NOT LIKE '%".$excludewords."%'
OR function NOT LIKE '%".$excludewords."%'
OR duties NOT LIKE '%".$excludewords."%'
OR achievements NOT LIKE '%".$excludewords."%'
OR reason_for_leaving NOT LIKE '%".$excludewords."%'))
UNION
(SELECT account_id FROM personal
WHERE
actual_city LIKE '%".$includelocation."%'
AND
actual_city NOT LIKE '%".$excludelocation."%'
)
UNION
(SELECT account_id FROM education
WHERE
institution LIKE '%".$school."%' OR
grade_achieved LIKE '%".$school."%'
)
";
$count="SELECT COUNT account_id FROM
(SELECT account_id FROM work
WHERE
(company LIKE '%".$includewords."%'
OR function LIKE '%".$includewords."%'
OR duties LIKE '%".$includewords."%'
OR achievements LIKE '%".$includewords."%'
OR reason_for_leaving LIKE '%".$includewords."%')
AND
(company NOT LIKE '%".$excludewords."%'
OR function NOT LIKE '%".$excludewords."%'
OR duties NOT LIKE '%".$excludewords."%'
OR achievements NOT LIKE '%".$excludewords."%'
OR reason_for_leaving NOT LIKE '%".$excludewords."%'))
UNION
(SELECT account_id FROM personal
WHERE
actual_city LIKE '%".$includelocation."%'
AND
actual_city NOT LIKE '%".$excludelocation."%'
)
UNION
(SELECT account_id FROM education
WHERE
institution LIKE '%".$school."%' OR
grade_achieved LIKE '%".$school."%'
)";
第二脚本不起作用
mysqli_fetch_array()
期望参数1为mysqli_result,布尔在C:\ xampp \ htdocs]中给出
我有一个复杂的mysqli_query,它显示结果,但不计算在内。我应该两次运行相同的脚本?或其他建议? $ sql应该给我结果,而$ count应该精确计数...
答案
计算您想计算的领域周围的需求。请参阅:https://www.w3schools.com/sql/func_mysql_count.asp
另一答案
假设您有以下查询:
以上是关于MySQLi中的计数[重复项]的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Spark Scala 中的 Schema RDD [从案例类中创建] 中查找重复项以及相应的重复计数?
Javascript - 计算对象数组中的重复项并将计数存储为新对象