想要显示两张表中附加图像中提到的记录

时间:2016-10-21 05:33:47

标签: php mysql

我想以相同的格式显示两张表中的记录,如附加图像链接所示。请帮助如何通过PHP或MYSQL显示它。

Want to show the record as mentioned in attached image from two tables

<?php 
$con = @mysql_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password);
mysql_select_db( $mysql_db_database);

$res = mysql_query("SELECT  assembly, COUNT( CASE WHEN (`elect`.election_year =  '2013')  THEN  `tbl_observer_stats`.male_observers_trained ELSE NULL END ) AS '2013',
COUNT( CASE WHEN (`elect`.election_year =  '2014')  THEN  `tbl_observer_stats`.male_observers_trained   ELSE NULL END ) AS '2014',
COUNT( CASE WHEN (`elect`.election_year =  '2015')  THEN  `tbl_observer_stats`.male_observers_trained   ELSE NULL END ) AS '2015',
COUNT( CASE WHEN (`elect`.election_year =  '2016')  THEN  `tbl_observer_stats`.male_observers_trained   ELSE NULL END ) AS '2016',
COUNT( CASE WHEN (`elect`.election_year =  '2017')  THEN  `tbl_observer_stats`.male_observers_trained   ELSE NULL END ) AS '2017',
COUNT( CASE WHEN (`elect`.election_year =  '2018')  THEN  `tbl_observer_stats`.male_observers_trained   ELSE NULL END ) AS '2018'
FROM elect LEFT JOIN tbl_observer_stats ON (elect.id=tbl_observer_stats.election_id)  GROUP BY assembly") or die(mysql_error());
?>

<table width="812" class="listing resultList resultList--tbl_election" border="1">
        <tr class="table-headings">
        <th class="row-actions-header" width="157" rowspan="3"><div align="left"><strong>Assembly</strong></div></th>
        <th height="43" colspan="14" class="row-actions-header"><div align="center"><strong>Number of Observers Trained</strong></div></th>
              </tr>
              <tr class="table-headings">
                <th colspan="2" class="row-actions-header"><div align="center"><strong>2013</strong></div></th>
                <th width="74" colspan="2" class="row-actions-header"><div align="center"><strong>2014</strong></div></th>
                <th width="74" colspan="2" class="row-actions-header"><div align="center"><strong>2015</strong></div></th>
                <th width="74" colspan="2" class="row-actions-header"><div align="center"><strong>2016</strong></div></th>
                <th width="74" colspan="2" class="row-actions-header"><div align="center"><strong>2017</strong></div></th>
                <th width="114" colspan="2" class="row-actions-header"><div align="center"><strong>2018</strong></div></th>
                <th width="141" colspan="2" class="row-actions-header"><div align="center"><strong>Total</strong></div></th>
              </tr>
              <tr class="table-headings">
                <th width="30" height="43" class="row-actions-header">Male Observer</th>
                <th width="16" class="row-actions-header">Female Observer</th>
                <th class="row-actions-header">Male Observer</th>
                <th class="row-actions-header">Female Observer</th>
                <th class="row-actions-header">Male Observer</th>
                <th class="row-actions-header">Female Observer</th>
                <th class="row-actions-header">Male Observer</th>
                <th class="row-actions-header">Female Observer</th>
                <th class="row-actions-header">Male Observer</th>
                <th class="row-actions-header">Female Observer</th>
                <th class="row-actions-header">Male Observer</th>
                <th class="row-actions-header">Female Observer</th>
                <th class="row-actions-header">Male Observer</th>
                <th class="row-actions-header">Female Observer</th>
       </tr> 

      <?php  while($result = mysql_fetch_assoc($res)) {?>  

      <tr class="table-headings">
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td>
      <td class="field-content resultListCell">&nbsp;</td> 
      <td class="field-content resultListCell">&nbsp;</td> 
      <td class="field-content resultListCell">&nbsp;</td>
      </tr>
      <?php  }?>

        </table>

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题:

clients