我想按类别和子类别进行分类。我从用户表中选择了子类别ID。我得到了这个:
Sports Cricket
Sports Basketball
Sports Volley Ball
News Political
News Business
News Entertainment
但我需要它是这样的:
Sports
Cricket
Basketball
Volley Ball
News
Political
Business
Entertainment
这是我的代码:
<?
$row = mysqli_fetch_array(mysqli_query($con,"select * from user where UserId ='3' and Status='act'"));
$show_str = $row["SubcatId"];
$fas = mysqli_query($con, "select * from subcategory where Status='act' ORDER BY catId Asc");
while($ad = mysqli_fetch_array($fas)){
$SubCategory = $ad["SubCategory"]; //Sub Category Name
$SubCatId = $ad["SubCatId"]; //Sub Category Id
$catId = $ad["catId"]; //Category Id
$array = explode(",", $show_str);
foreach($array as $item){
if($item == $SubCatId){
$fac = mysqli_fetch_array(mysqli_query($con, "select distinct Category from category where catId='$catId'"));
echo $Category = $fac["Category"];
?>
<?=$SubCategory;?>
<br>
<?php
}
}
}
?>