jefffogel1974 Posted June 14, 2009 Share Posted June 14, 2009 I am building a web application that list band names in the right column and in the left column the number of songs in my DB for each band. But I cant get it to work correctly. Can anyone help with this and let me know what im doing wrong in the code. URL http://www.xtremetab.com/tablatureDB/test.php Code <?php $data = mysql_query("SELECT DISTINCT AllBands FROM Allsongs WHERE SUBSTR(LCASE(AllBands),1,1) = LCASE('1') ORDER BY AllBands ASC LIMIT 1,50"); echo '<table width="100%">'; echo '<tr><td>Artists:</td><td># of songs:</td></tr>'; while($result = mysql_fetch_assoc($data)){ $_sql = mysql_query("SELECT DISTINCT(AllSongs) as SongCount FROM allsongs WHERE AllSongID='".$result['AllSongID']."'"); $count['SongCount']; echo '<tr>'; echo '<td>'.$result['AllBands'].'</td>'; echo '<td>[ <strong>'.$count['SongCount'].'</strong> Songs ]</td>'; echo '</tr>'; } echo '</table>'; ?> Link to comment https://forums.phpfreaks.com/topic/162111-need-help-with-php-mysql-count-syntax/ Share on other sites More sharing options...
pkedpker Posted June 14, 2009 Share Posted June 14, 2009 is $count is variable did you mean count()... http://us3.php.net/count Link to comment https://forums.phpfreaks.com/topic/162111-need-help-with-php-mysql-count-syntax/#findComment-855456 Share on other sites More sharing options...
joel24 Posted June 14, 2009 Share Posted June 14, 2009 you're not counting the songs at all? or pulling the results into a variable..? <?php $data = mysql_query("SELECT DISTINCT AllBands FROM Allsongs WHERE SUBSTR(LCASE(AllBands),1,1) = LCASE('1') ORDER BY AllBands ASC LIMIT 1,50"); echo '<table width="100%">'; echo '<tr><td>Artists:</td><td># of songs:</td></tr>'; while($result = mysql_fetch_assoc($data)){ $_sql = mysql_query("SELECT DISTINCT(AllSongs) as SongCount FROM allsongs WHERE AllSongID='".$result['AllSongID']."'"); //count the number of rows returned by the previous SQL query $songCount = mysql_num_rows($_sql); echo '<tr>'; echo '<td>'.$result['AllBands'].'</td>'; echo '<td>[ <strong>'.$songCount.'</strong> Songs ]</td>'; echo '</tr>'; } echo '</table>'; ?> Link to comment https://forums.phpfreaks.com/topic/162111-need-help-with-php-mysql-count-syntax/#findComment-855462 Share on other sites More sharing options...
Mark Baker Posted June 14, 2009 Share Posted June 14, 2009 SELECT AllBands, COUNT(AllSongs) FROM Allsongs WHERE SUBSTR(LCASE(AllBands),1,1) = LCASE('1') GROUP BY AllBands ORDER BY AllBands ASC Link to comment https://forums.phpfreaks.com/topic/162111-need-help-with-php-mysql-count-syntax/#findComment-855501 Share on other sites More sharing options...
jefffogel1974 Posted June 14, 2009 Author Share Posted June 14, 2009 Hi Joel Once I put in the $songCount = mysql_num_rows($_sql); on line 17 it returns errors, check out the page below. http://www.xtremetab.com/tablatureDB/test.php Am I missing something? Link to comment https://forums.phpfreaks.com/topic/162111-need-help-with-php-mysql-count-syntax/#findComment-855579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.