peehaichpee Posted March 15, 2012 Share Posted March 15, 2012 I'm trying to work out a count of how many of what assets are in a certain location: there should be 13 different categories (asset types) in a location and i want the individual count of each category. here's what i have - which seems to give me a total count of all assets and locations together plus one asset description and one location..... almost right. $con = mysql_connect('localhost','root',''); if(! $con) die(mysql_error()); mysql_select_db("test",$con); $result = mysql_query("SELECT DISTINCT COUNT(`Asset Description`) AS TOTALAD, LOCATION, `Asset Description` AS AD FROM master WHERE LOCATION like 'NC%'"); while($row = mysql_fetch_array($result)) { echo $row["LOCATION"]; echo "<br />"; echo $row["TOTALAD"]; echo "<br />"; echo $row["AD"]; echo "<br />"; } mysql_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/258969-sql-count-statement-this-is-probably-really-simple/ Share on other sites More sharing options...
darkfreaks Posted March 15, 2012 Share Posted March 15, 2012 you query is abit out of order. it should be like SELECT COUNT (DISTINCT `Asset Description`) AS TOTALAD, LOCATION, `Asset Description` AS AD FROM master WHERE LOCATION like 'NC%' Quote Link to comment https://forums.phpfreaks.com/topic/258969-sql-count-statement-this-is-probably-really-simple/#findComment-1327551 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.