perficut Posted October 29, 2008 Share Posted October 29, 2008 I have a table that consists of names and addresses. |FIRST|LAST|CITY|STATE|ZIP If I want to count how many members are from a particulare state how can I do that. I use the state abbreviations in my database. heres what I have but obviosly it doesnt work. // Make a MySQL Connection $query = "select COUNT(*) from MDSRContractor WHERE State='IN'"; $result = mysql_query($query) or die(mysql_error()); $totalfromIN = mysql_fetch_array($result); echo $totalfromIN; Quote Link to comment https://forums.phpfreaks.com/topic/130578-solved-how-to-count-only-one-entry-type/ Share on other sites More sharing options...
trq Posted October 29, 2008 Share Posted October 29, 2008 $query = "select COUNT(*) AS foo from MDSRContractor WHERE State='IN'"; $result = mysql_query($query) or die(mysql_error()); $totalfromIN = mysql_fetch_array($result); echo $totalfromIN['foo']; Quote Link to comment https://forums.phpfreaks.com/topic/130578-solved-how-to-count-only-one-entry-type/#findComment-677450 Share on other sites More sharing options...
perficut Posted October 29, 2008 Author Share Posted October 29, 2008 Thanks, I think that did it. Quote Link to comment https://forums.phpfreaks.com/topic/130578-solved-how-to-count-only-one-entry-type/#findComment-677477 Share on other sites More sharing options...
fenway Posted October 30, 2008 Share Posted October 30, 2008 You can use mysql_result( $result, 0, 0 ) and then you don't need an alias, either. Quote Link to comment https://forums.phpfreaks.com/topic/130578-solved-how-to-count-only-one-entry-type/#findComment-678534 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.