# Trouble using sql count

**URL:** <https://forum.kirupa.com/t/trouble-using-sql-count/245493>\
**Category:** Uncategorized\
**Created:** [November 30, 2007, 7:04am UTC](https://forum.kirupa.com/t/trouble-using-sql-count/245493 "2007-11-30T07:04:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tge1986](https://avatars.discourse-cdn.com/v4/letter/t/ba8739/32.png) [@tge1986](https://forum.kirupa.com/u/tge1986)\
**Post date:** [November 30, 2007, 7:04am UTC](https://forum.kirupa.com/t/trouble-using-sql-count/245493/1 "2007-11-30T07:04:34Z")

</div>

I’m trying to count how many posts there are from each state in a table in my db ideally it would put the number in an array 0-49 alphabetically in order of states, but i can’t seem to get it to work this is the code so far.

$q = “SELECT CompanyState, count(\*) AS Number FROM job\_post GROUP BY CompanyState ORDER BY CompanyState”;  
$result = mysql\_query($q);  
$result2 = mysql\_fetch\_array($result);

when i echo out the array it only shows the first post count which is Alabama but i can’t get any others. is there a way to only select the counts in order? I then want to output it to a flash movie, but i think I can do that if i can get this to work. Thanks for your help!
