我正在访问数据库中以逗号分隔的类别字段,这些字段作为重复数据。如何只显示唯一值?
这是我的代码。
<?php
include($_SERVER["DOCUMENT_ROOT"]."/dbconnect.php");
$sql = "SELECT DISTINCT cats FROM videos ORDER BY cats";
$result = mysqli_query($conn, $sql);
echo "<div class='row'>
<div class='large-12 columns'>";
echo "<a href='index.php'><span class='filter-label info'>All</span></a>";
while($rows=mysqli_fetch_assoc($result)){
$cats = $rows['cats'];
$filter = explode(',', $cats);
foreach($filter as $filter) {
echo "<a href='index.php?cats=".$filter."'><span class='filter-label info'>".$filter."</span></a>";
}
}
echo "</div>
</div>";
?>