By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

How to count a $result

P: 52
the query below output's 2222222222

How do I get it to count the number of 2's and give the answer 10

[PHP]$query4 = ("SELECT hometeam FROM conference_results WHERE hometeam = '".$teamnamesid."' AND season LIKE '2006-07' ");
$result4 = mysql_query($query4) or die(mysql_error());
while($row = mysql_fetch_array($result4))
{
$hometeam = $row['hometeam'];
echo"$hometeam";}[/PHP]
Aug 4 '07 #1
Share this Question
Share on Google+
4 Replies


pbmods
Expert 5K+
P: 5,821
Heya, hinksta.

You'll want to use strlen() for that.
Aug 4 '07 #2

P: 52
Thanks pbmods,

I not sure that will work for this. Some info I neglected to add is that each number is an occurrence of a mysql "id".

Also each number has a space between it like 15 15 15 15 15 15, the return from this one would want to be 6.
Aug 5 '07 #3

ilearneditonline
Expert 100+
P: 130
the query below output's 2222222222

How do I get it to count the number of 2's and give the answer 10

[PHP]$query4 = ("SELECT hometeam FROM conference_results WHERE hometeam = '".$teamnamesid."' AND season LIKE '2006-07' ");
$result4 = mysql_query($query4) or die(mysql_error());
while($row = mysql_fetch_array($result4))
{
$hometeam = $row['hometeam'];
echo"$hometeam";}[/PHP]
I am not sure if this is what you are looking for. But the following SQL should show you the total number of times for each team.
[PHP]$query = "SELECT hometeam, count(hometeam) as thecount FROM
conference_results WHERE hometown='".$teamnamesid."'
AND season LIKE '2006-07' GROUP BY hometeam";[/PHP]
Aug 5 '07 #4

P: 52
Thanks,

That looks to be perfect, count(hometeam) as thecount is going to be very handy.
Aug 5 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.