RON_ron Posted September 8, 2010 Share Posted September 8, 2010 my mysql has got a field called statez where it stores the STATE. How do I amend the code below by adding $SomeVar = $_POST['Hamburg']; to count the number of records of a particular state? ($SomeVar will represent the state) $query = "SELECT statez, COUNT(statez)FROM distributors GROUP BY statez"; $results = mysql_query($query); $returnS=""; while($line = mysql_fetch_array($results)) { $returnS.= $line['COUNT(statez)'].",,".$line['statez'].",,,"; } echo $returnS; Link to comment https://forums.phpfreaks.com/topic/212847-count-similar-records/ Share on other sites More sharing options...
trq Posted September 8, 2010 Share Posted September 8, 2010 I'm not sure this is what you mean. $state = mysql_real_escape_string($_POST['Hamburg']); $query = "SELECT statez, COUNT(statez) FROM distributors WHERE statez = '$state'"; Link to comment https://forums.phpfreaks.com/topic/212847-count-similar-records/#findComment-1108622 Share on other sites More sharing options...
RON_ron Posted September 8, 2010 Author Share Posted September 8, 2010 Perfect! Thanks. Link to comment https://forums.phpfreaks.com/topic/212847-count-similar-records/#findComment-1108633 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.