これが私のクエリです。テーブルの最後に、3 つの「SUM」フィールドの合計がありますが、テキスト「TOTAL」は出力されません。助言がありますか?
$query = 'SELECT
IFNULL(fields_info.field_num,"TOTAL") AS `ff`,lands.city, farmers.first_name, farmers.last_name, seasons.season,
SUM(fields_info.acreage) AS a,
SUM(fields_info.using_acreage) AS ua,
SUM(fields_info.unusing_acreage) AS una
FROM fields
LEFT JOIN regions ON id_region = regions.id
LEFT JOIN lands ON regions.id_lands = lands.id
LEFT JOIN fields_info ON id_fields_info = fields_info.id
LEFT JOIN farmers ON id_farmer = farmers.id
LEFT JOIN seasons ON id_season = seasons.id
WHERE CONCAT(farmers.first_name, " ", farmers.last_name) = \''.mysql_real_escape_string($_POST['fnzp']).'\'
AND seasons.season = \''.mysql_real_escape_string($_POST['season']).'\'
GROUP BY ff WITH ROLLUP';
これはテーブルを作成するための私のコードです:
$sql_select = mysql_query($query) or die(mysql_error());
$sql_select1 = mysql_query($query) or die(mysql_error());
$row1 = mysql_fetch_array($sql_select1);
echo "<table border='1' id='result_table'>
<tr>
<th>Name</th>
<td class='tdata'>".$row1['first_name']. " " .$row1['last_name']."</td>
</tr>
<tr>
<th>Land</th>
<td class='tdata'>".$row1['city']."</td>
</tr>
<tr>
<th>Season</th>
<td class='tdata'>".$row1['season']."</td>
</tr>
<tr>
<td colspan='4'> </td>
</tr>
<tr>
<th>Field num</th>
<th>Field acreage</th>
<th>Using acreage</th>
<th>Unusing acreageема площ</th>
</tr>
";
if($query != "" && mysql_num_rows($sql_select) > 0 ) {
while($row = mysql_fetch_assoc($sql_select))
{
echo "<tr>";
echo "<td>" . $row['ff'] . "</td>";
echo "<td>" . $row['a'] . "</td>";
echo "<td>" . $row['ua'] . "</td>";
echo "<td>" . $row['una'] . "</td>";
echo "</tr>";
}
}
else
{
echo '<tr><td colspan="5">No records in db.</td></tr>';
}
echo "</table>";
全体として、最後の行に「合計」が表示されていることを除いて、すべてが正常に機能しています。