1
我在使結果正常工作時遇到問題。我有兩個疑問,一個是把所有俱樂部的信息都放到桌子上,另一個是統計表中每個俱樂部的總人數。從兩張不同表格的總數中得到的總數
問題是總數顯示不正確,在桌子上的最後一個單元格之後,而不是像我打算顯示它一樣。
下面是它的外觀:
這裏是我的查詢:
對於表格
$sql = "SELECT id, nombreClub, liderVoluntario, region, municipio, oficinaLoc
FROM club4h
ORDER BY region, oficinaLoc";
對於總計
$sql = "SELECT count(soc.nombreClub)
FROM socios as soc
RIGHT OUTER JOIN club4h as club
ON soc.nombreClub = club.nombreClub
GROUP BY club.id";
和我如何顯示錶
<table>
<?php
$name = '';
$filler = '';
echo '<tr>
<th>Región</th>
<th>Unidad Programática</th>
<th>Nombre Club</th>
<th>Lider Voluntario</th>
<th>Localización Club</th>
<th>Total Socios</th>
</tr>';
foreach($result as $key=>$row){
echo'<tr>
<td>'.ucfirst($row['region']).'</td>';
if(($row['id']) !=$filler) echo
'<td>'.ucfirst($row['oficinaLoc']).'</td>';
$filler = $row['id'];
echo '<td>'.ucfirst($row['nombreClub']).'</td>
<td>'.ucfirst($row['liderVoluntario']).'</td>
<td>'.ucfirst($row['municipio']).'</td>';
}
include_once 'sociocount.php';
foreach($memberSearch as $total){
echo '<td>'.$memberSearch[$i][0].'</td>
</tr>';
$i++;
}
?>
</table>
代碼難道這在單個查詢做到嗎?或者我做錯了什麼,它導致它被顯示那樣?
是的,你可以在一個查詢中做到這一點。基本上它是 - * SELECT SUM('members'),'club' FROM'table' GROUP BY'club' * –