Question:
mysql count?
chillimoto
2008-02-03 22:59:04 UTC
i have table A(id,location_id) & table B(id,location_name) which A.location_id refers to B.id. B is a list table. So, how can i count how many locations in A referring to B and show zero(0) for each location in B if non referred in A. eg:

A B
--- ----
1:1 1:ps
2:1 2:ok
3:5 3:bc
4:6 4:sa
5:2 5:pm
6:gp

in return...

name : total
--------------
ps :2
ok :1
bc :0
sa :0
pm :1
gp :1
Three answers:
Casey
2008-02-03 23:03:36 UTC
This question makes little to no sense.

Ever try

$db = mysql_query("SELECT * FROM `b` WHERE `id` = 'VALUE_HERE'");

$count = mysql_num_rows($db);

print $count;
D&I Office Technology
2008-02-04 07:30:51 UTC
Okay, This question makes sense... but takes a little bit of thinking to understand correctly.



Simply query these table A or B into an array and then use a loop and query with the WHERE a = b method to increase an counter variable... If you really need help on this i will try to code something. Just give me a yell and i will...



But if you cant use a sql query to get the results, i start with arrays n variables to hold data that way i have the data and can still query without using multiple connections and so on.



the zero or return value would be an if statement on the mysql count return
anonymous
2014-11-19 09:10:30 UTC
very confusing point. look into using bing and yahoo. this can help!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...