limitphp Posted February 20, 2009 Share Posted February 20, 2009 If I have a query: $querySongs = "SELECT COUNT(songID) FROM vote WHERE songID = '$songID'"; $resultSongs = mysql_query($querySongs) or die (mysql_error()); $rowSongs = mysql_fetch_assoc($resultSongs); How do I grab the COUNT(songID)? like this: $count = rowSongs[COUNT(songID)]; ?? thanks.... by the way, whoevr wrote that tutorial on UNION JOINS thank you so much....awesome tutorial. I learned so much about the proper way to structure queries and logically break down what they are doing. Link to comment https://forums.phpfreaks.com/topic/146167-solved-help-grabbing-count/ Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 $querySongs = "SELECT COUNT(songID) as SongCount FROM vote WHERE songID = '$songID'"; $resultSongs = mysql_query($querySongs) or die (mysql_error()); $rowSongs = mysql_fetch_assoc($resultSongs); echo $rowSongs['SongCount']; Should do it. Using the "AS" keyword allows you to create an alias of the actual field (essentially renames it when it is fetched). EDIT: To not use the "as" this would also work. And actually I prefer this way for these type of queries: $querySongs = "SELECT COUNT(songID) FROM vote WHERE songID = '$songID'"; $resultSongs = mysql_query($querySongs) or die (mysql_error()); $rowSongs = mysql_result($resultSongs, 0); echo $rowSongs; As you just pull that first column out Link to comment https://forums.phpfreaks.com/topic/146167-solved-help-grabbing-count/#findComment-767395 Share on other sites More sharing options...
angelcool Posted February 20, 2009 Share Posted February 20, 2009 This should also work without using as (s lol ) in you query: $rowSongs = mysql_fetch_array($resultSongs); echo $rowSongs[0]; Angel Link to comment https://forums.phpfreaks.com/topic/146167-solved-help-grabbing-count/#findComment-767399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.