<?php require_once('../includes/connection.php');?>
<?php require_once('../includes/header.php');?>
<?php
$color="1";
$respo = $_GET['respo'];
$data = explode("+", $respo);
$month = date("m", strtotime($data[1])) . "<br />";
$year = date("Y", strtotime($data[1])) . "<br />";
**$viewrecord = "SELECT *, (pr.roll1 + pr.roll2 + pr.roll3 + pr.roll4 + pr.roll5 + pr.roll6) AS rolls FROM tbl_payroll dv join tbl_payroll pr on pr.dv_id = dv.dv_id WHERE dv.respo='".mysql_real_escape_string($data[0])."' && year(dv.date_added)='$year' && month(dv.date_added)='$month'";**
$run_viewrecord = mysql_query($viewrecord) or die(mysql_error());
{
echo "<table border='1' width='100%' style='border:1px solid silver' cellpadding='5px' cellspacing='0px'>
<tr bgcolor='#666666' style='color:#FFFFFF'>
<th>Date Encoded</th>
------------HEADER--------- etc....
-------THERE SHOULD BE A IF STATEMATE HERE-----------------
(where if no records match "dv.dv_id=pr.pr.dv_id". It would still display records from tbl_dv..)
while ($row = mysql_fetch_row($run_viewrecord)) {
if($color==1){
echo "<tr bgcolor='#ffffff'>";
echo "<td align='center'>" .date_format(date_create($row[17]), "m/d/y")."</td>
**--------- I WANT TO DISPLAY THE ROLLS HERE --------------------**
echo "</td></tr>";
$color="2";
} else {
echo "<tr bgcolor='#ebeaea'>";
echo "<td align='center'>" .date_format(date_create($row[17]), "m/d/y")."</td>
**--------- I WANT TO DISPLAY THE ROLLS HERE --------------------**
echo "</td></tr>";
$color="1";
}
}
echo '</table>';
echo '<td><tr><table><br /><br />';
}
?>
我希望在WHILE之前添加一个IF语句。即使桌面2上没有匹配的dv_id,仍然会显示记录。它应该仍然显示记录.. COLUMN ROLLS如果不匹配它将显示0.00值。 LINK&GT;&GT; http://i599.photobucket.com/albums/tt79/emcevo/viewphpdisplay_zpsfc6a8174.jpg
//Total NET
<?php
$qry2 = "SELECT *, SUM(net) as sum_net FROM tbl_dv";
$run2 = mysql_query($qry2) or die(mysql_error());
while ($row = mysql_fetch_array($run2)) {
?>
<tr>
<td colspan="5" style="text-align:right;" /><b>TOTAL NET</b></td>
<td colspan="6" style="text-align:left;font-size: 14px;" /><b><?php echo number_format($row['sum_net'],2); ?></b></td>
</tr><?php }?>
</td></tr></table>
如何在代码下方显示TOTAL NET:
$qry2 = "SELECT *, SUM(net) as sum_net FROM tbl_dv";.
我的顶级代码都在工作..粗体的BUTTOM代码是问题。
答案 0 :(得分:0)
我猜你得到了downvotes,因为我看到你的整个php代码块是不必要的。您的查询“$ qry2”不正确;你不能没有一个小组的总和(除非你只做一笔钱)。例如:
select dv_id, sum(net) as sum_net from tbl_dv group by dv_id