Two arrays, how to 'line them up'
Posted: Tue Aug 29, 2006 10:26 pm
Hi all,
I have two arrays, one contains a list of individual postcodes: IE
The other is an array with JUST the count of each postcode.
IE: if the postcodes were:
Then the array $postcode_count would contain:
What I want is a display that shows the postcode and the number of that postcode that has been counted in the database:. IE:
How can I get this data to match up?
(scratching head for too long now
)
Rob
I have two arrays, one contains a list of individual postcodes: IE
Code: Select all
//get the postcodes from the database and stick it in an array. sticking in ALL postcodes so we can count the numbers!!!
//=======================================================================================================================
mysql_select_db($dbname);
$sql = "SELECT * FROM clients ORDER BY add_pcode";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$cShowMax = mysql_num_rows($content);
//setup the array before we loop through and push data in it
$pcode_number_array = array();
for ($y=1; $y<=$cShowMax; $y++)
{
//Get the info from the database and smack it in variables for user later
$pcode_id = $Xcontent["id"]; //get the Post Code
$add_pcode = $Xcontent["add_pcode"]; //get the Post Code
//stick them into an array
array_push($pcode_number_array, "$add_pcode");
$Xcontent = mysql_fetch_array($content);
}The other is an array with JUST the count of each postcode.
Code: Select all
//count the number of postcodes by group
$postcode_count = array_count_values($pcode_number_array);Code: Select all
4000, 4000, 4000, 4001, 4002, 4006, 4006, 4008Code: Select all
3, 1, 1, 2, 1Code: Select all
4000 3
4001 1
4002 1
4006 2
4008 1(scratching head for too long now
Rob