PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
//get the postcodes from the database and stick it in an array
//========================================================
mysql_select_db($dbname);
$sql = "SELECT * FROM clients ORDER BY add_pcode ASC";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$cShowMax = mysql_num_rows($content);
for ($y=1; $y<=$cShowMax; $y++)
{
//Get the info from the database and smack it in variables for user later
$client_id = $Xcontent["id"]; //get the client id, just in case?
$add_pcode = $Xcontent["add_pcode"]; //get the clients Post Code
//stick the post code into an array
$pcode_array["$postcode"] = $add_pcode;
$Xcontent = mysql_fetch_array($content);
}
I guess, now I have it there, what can I do with it? A logic example would even be appreciated as I can work out the code from that I'm sure... Unless of course there's some super cool function out there?
That looks like a wicked function, never seen it before. Perhaps I'm wrong, but it doesn't seem to allow me to show how many clients there are in each post code. Can it do that?
Currently if I try it, I just get back the individual postcodes (which is great) but i need to see how many clients share each post code. I need to see which areas my clients are coming from.
Thanks a tonne.
Rob
PS please don't tell me a join is needed. I for the life of me can't get them in my head
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in d:\sites\salon\report_type_postcode_breakdown.php on line 158
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in d:\sites\salon\report_type_postcode_breakdown.php on line 159
I'm not really sure what's wrong. I can show a bit of the CLIENTS table if this helps?:
ok, no error now, but well, i presume i need an explination on how it all works. I really appreciate the code but i don't quite understand it (although it seems to work )
I'm wondering if someone could sort of, spell out the meaning of that? If you have time. I understand people are busy though, but if there is someone out there, then thank you.
Also I'm wondering, how can I get the value of cnt to display the count with an echo. ie: echo "$cnt";
As you can see, I'm not quite comprehending what's happening here
mmm, that tutorial seems to suffer the same that all the other tutorials do on the topic. They all give the example of calculating the sum of a particular field. What I'm after is finding out how many items are in each group after performing the GROUP BY.
postcode number of clients in postcode
4000 5
4500 2
4090 3
None of the tutorials I've found so far show how to handle this, and as a newby on this topic I really don't know much about it to go and feel it out just yet.
robster wrote:mmm, that tutorial seems to suffer the same that all the other tutorials do on the topic. They all give the example of calculating the sum of a particular field. What I'm after is finding out how many items are in each group after performing the GROUP BY.
Hmmz, that user seems to suffer the same that all users do on the topic: They don't make clear what they really want to do
What I need to figuire out is how I can then parse through the array and find (count) the matching post codes.
Do you want to count how many other clients have the same pcode?
SELECT c1.client_id, count(*)
FROM clients AS c1
OUTER JOIN clients AS c2 ON c1.pcode = c2.pcode
WHERE c1.client_id <> c2.client_id
GROUP BY c1.client_id