【发布时间】:2015-05-27 09:05:59
【问题描述】:
<select>
<?php
require 'dbc.php';
$getallnature_query = "SELECT strnature, Count(*) as total FROM nature_tbl GROUP BY strnature";
$getallnature_stmt = $db->prepare($getallnature_query);
$getallnature_stmt->execute();
$getallnature_stmt->bind_result($allnature,$count);
while ($getallnature_stmt->fetch()) {
echo "<option>$allnature </option>";
}
?>
</select>
问题。我想将我的自然表中的所有数据提取到 SELECT OPTION 中。我的问题是结果返回所有重复的记录。
我使用 count(*) 来防止重复记录。但仍然无法正常工作。你能告诉我如何合并重复记录吗?
我的代码产生这样的结果
<select>
<option>Aircon unit</option>
<option>Aircon unit</option>
<option>Others </option>
</select>
【问题讨论】:
-
尝试使用 distinct - SELECT DISTINCT strnature FROM nature_tbl
-
我相信这是我的错。我的代码正在运行。我只是在数据库中输入带有空格的“空调单元”。这就是为什么它同时显示。顺便说一句,DISTINCT WORK ALSO !但是计数或区分的最新方法是什么?
-
如果你不需要count就用我提供的sql,会快很多。
-
谢谢!感谢您的宝贵时间!
标签: php mysqli duplicates