php - Combine total count for entries in 2 SQL tables -



php - Combine total count for entries in 2 SQL tables -

i can't seem find right way hoping give me direction?

the sql database structured (i've removed irrelevant stuff):

requests r_id r_fulfilledby 1 bob 2 craig 3 bob sims sm_id sm_fulfilledby 1 bob 2 craig 3 bob

i'm hoping end output:

fulfilled requests bob 4 craig 2

here's php/html:

<div id="table"> <?php //connect mysql database $connection = mysql_connect($runnerdbserver, $runnerdbuser, $runnerdbpass); mysql_select_db($runnerdbname, $connection) or die("mysql error"); $query = "select r_fulfilledby, count(r_id) requests grouping r_fulfilledby order count(r_id) desc"; $result = mysql_query($query) or die(mysql_error()); ?> <!-- number of runners (counts total number of records in requests table) --> <table border='0' width='50%'> <tr> <th>runners fulfilled</th> <tr><td><?php $query = mysql_query("select * requests"); $number=mysql_num_rows($query); echo $number; ?> </td></tr> </table> &nbsp; <!-- fulfillment stats --> <table border='0' width='50%'> <tr> <th>name</th> <th>runners fulfilled</th> </tr> <? // print out result (i want calculate requests fulfilled each user in 'requests' , 'sims' table) while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td>". $row['r_fulfilledby'] ."</td>"; echo "<td>". $row['count(r_id)'] ."</td>"; echo "</tr>"; } ?> </table>

at nowadays it's calculating records 'requests' table :(

you union all 2 tables in subquery:

select fulfilledby , count(*) ( select r_fulfilledby fulfilledby requests union select sm_fulfilledby sims ) subqueryalias grouping fulfilledby

use union all instead of union because sec eliminates duplicates; give maximum count of 1.

php mysql html sql count

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -