Jump to content

Recommended Posts

Hi everyone, I am currently using the following code:

 

<?php
$stats = mysql_query("SELECT * FROM totalCalls WHERE operatorId = '".$operatorId."'") or die(mysql_error());
$morestats = mysql_query("SELECT typeId, COUNT(*) as numcalls FROM totalCalls WHERE operatorId = '".$operatorId."' GROUP BY typeId") or die(mysql_error());
$res = mysql_query("SELECT * FROM typeOfCalls ORDER BY typeId") or die(mysql_error());
$total = mysql_num_rows($stats);
echo "<div id=\"rightborder\">";
echo "<div class=\"right\">";
echo "<table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "Total Calls Answered Today: $total";
echo "<br />";
while ($row1 = mysql_fetch_assoc($res)) {
while ($row = mysql_fetch_assoc($morestats)) {
$rowz = $row["numcalls"];
echo"<tr>";
echo "<td>" .$row1['type']. "</td>";
echo "<td>$rowz</td>";
echo "</tr>";
}
}
echo "</table>";
echo "</div></div>";
?>

 

I am just starting to use joins and have had sucess. But now I am trying to use th COUNT(*) syntax in the MySQL Statement... but could not get it to work. When I tried it, it was counting both tables and I need it to only count typeId. I got it working... somewhat using the code above with a nested while loop but it  echoes the "$row['type']"

like this:

 

Duel Sport

Duel Sport

Duel Sport

 

Instead of...

Duel Sport

Single Sport

Sports

 

Is it possible to combine the two SELECT statement from my code above and have it function, only using the COUNT on one table?

 

If so, what is the proper syntax? Thanks guys.

 

SC

Link to comment
https://forums.phpfreaks.com/topic/54804-possible-to-do-a-join-also-using-count/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.