suttercain Posted June 8, 2007 Share Posted June 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54804-possible-to-do-a-join-also-using-count/ Share on other sites More sharing options...
Barand Posted June 8, 2007 Share Posted June 8, 2007 try using COUNT(DISTINCT typeid) which will tell you howmany differnt types there are. Quote Link to comment https://forums.phpfreaks.com/topic/54804-possible-to-do-a-join-also-using-count/#findComment-271161 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.