这是我的查询,在表的末尾,我有三个“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>";
总而言之,除了在最后一行显示“总计”之外,一切都运行良好。