cgchris99 Posted July 12, 2003 Share Posted July 12, 2003 I have a bunch of event records for various event dates. I want to write an select state that shows the following State Count AZ 50 AR 2 AK 450 CO 75 CT 92 etc. sorted by state of course. How do I do this. thanks for any help Link to comment https://forums.phpfreaks.com/topic/708-counting-total-recs-for-each-state/ Share on other sites More sharing options...
Avalanche Posted July 12, 2003 Share Posted July 12, 2003 What I would use is: [php:1:c0bb7aeddb]$query = mysql_query(SELECT * FROM table ORDER BY state DESC); while($r=mysql_fetch_array($query)) { // cycle through states $state=$r[\"state\"]; // turn row variable to regular variable $count=$r[\"count\"]; // turn row variable to regular variable echo \"$state $count<br>n\"; // display state and count }[/php:1:c0bb7aeddb] That should loop through each different one displaying the state and count (assuming your column names are state and count... otherwise you need to change the $r[\"columnhere\"]). If it ends up in the reverse direction of what you want then change the DESC to ASC in the query. Good luck. Link to comment https://forums.phpfreaks.com/topic/708-counting-total-recs-for-each-state/#findComment-2345 Share on other sites More sharing options...
effigy Posted July 13, 2003 Share Posted July 13, 2003 if you have multiple state entries use: select count(*), state from table group by state Link to comment https://forums.phpfreaks.com/topic/708-counting-total-recs-for-each-state/#findComment-2346 Share on other sites More sharing options...
Avalanche Posted July 13, 2003 Share Posted July 13, 2003 Oh, whoops... I missread the question. He wanted to know how many records have that state... sorry, heheheh... :? Link to comment https://forums.phpfreaks.com/topic/708-counting-total-recs-for-each-state/#findComment-2349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.