php - Group by 'column name' doesn't seem to work -
i trying fetch category name has been saved multiple times before. fetch name need group name doesn't display multiple times, tried doing in way mentioned before , have failed far. i'm sure doing horribly wrong here , not able find why not able group it. appreciated. thanks.
$valsubcat=mysqli_query($conn,"select categoryid subcategorymaster subcatid=$valitem1[0]"); while($valsubcat1=mysqli_fetch_array($valsubcat)) { $valcat=mysqli_query($conn,"select categoryname categorymaster categoryid=$valsubcat1[0] group categoryname"); while($valcat1=mysqli_fetch_array($valcat)) { echo "<tr><td>".$valcat1[0]."</td></tr>"; } }
you can reduce 1 query using join
$sql = "select distinct scm.categoryid, cm.categoryname subcategorymaster scm left join categorymaster cm on cm.categoryid = scm.categoryid scm.subcatid = {$valitem1[0]}");
Comments
Post a Comment