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 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. 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"); ?> 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
Archived
This topic is now archived and is closed to further replies.