scarhand Posted November 4, 2008 Share Posted November 4, 2008 I am trying to output distinct band names, but count the amount of rows they take up in the database this is not working: $sql = mysql_query("SELECT DISTINCT(band), COUNT(band) as count FROM tabs WHERE band LIKE '$letter%' LIMIT 100"); while ($row = mysql_fetch_array($sql)) { $band = $row["band"]; $count = $row["count"]; echo "$band - $count<br>"; } any help is appreciated Quote Link to comment https://forums.phpfreaks.com/topic/131319-solved-select-distinct-and-count/ Share on other sites More sharing options...
fenway Posted November 4, 2008 Share Posted November 4, 2008 Please post your solution. Quote Link to comment https://forums.phpfreaks.com/topic/131319-solved-select-distinct-and-count/#findComment-682110 Share on other sites More sharing options...
scarhand Posted November 4, 2008 Author Share Posted November 4, 2008 I figured this out: <?php mysql_query("SELECT DISTINCT(band), COUNT(band) AS count FROM tabs WHERE band REGEXP '^$letter' GROUP BY band"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/131319-solved-select-distinct-and-count/#findComment-682138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.