2013-05-22 159 views
0

我有reservationpostflight表。我必須在reservation表中查詢並查找postflight表中的數據。總結查詢結果

$query="select * from reservation where date(fdate) between '$datefrom' and '$dateto' and status in ('Flown') $aircraft order by $sort"; 
$result=mysql_query($query) or die(mysql_error()); 
echo "<div class='box'><table class='hovertable'> 
    <th>Flight Date</th> 
    <th>Client Name</th> 
    <th>Group Code</th> 
    <th>Aircraft</th> 
    <th>Block Time</th> 
    <th>Waiting Time</th> 
    <th>Charter Fee</th> 
    <th>Take-off and Landing Fee</th> 
    <th>Waiting Time Fee</th> 
    <th>Other Charges</th> 
    <th>Sub-Total</th> 
    <th>Value-added Tax</th> 
    <th>Total Service Invoice Amount</th> 
    <th>Reservation No.</th> 
    </tr>"; 

while($row=mysql_fetch_array($result)) 
{ 
    $rvno=$row['reservno']; 
    $yr=(string) date("Y"); 
    $rn=$yr."-".$rvno; 
    $a=mysql_query("select *, (fdf + fce + aef + hf + sfp) as 'tcharge' from postflight where reservno='$rvno'") or die(mysql_error()); 
    //$e=mysql_fetch_array($a); 
    while($b=mysql_fetch_array($a)) 
    { 
    echo"<tr><td>".$row['fdate']."</td><td>".$b['cliename']."</td><td>".$row['grpcode']."</td><td>".$row['acode']."</td><td>".$row['btime']."</td><td>".$b['wtime']."</td><td>".$b['total_cfee']."</td><td>".$b['total_tol']."</td><td>".$b['total_wtfee']."</td><td>".$b['tcharge']."</td><td>".$b['sub_total']."</td><td>".$b['vat']."</td><td>".$b['total_service_invoice_amt']."</td><td>".$rn."</td></tr>"; 
    } 

} 

之前我關閉</table>,我想補充另一排它總結了所有必需的字段基於上述查詢的輸出數據進行總結。類似的,

echo "<tr><td colspan='6'></td><td><b>sum</b></td><td><b>sum</b></td><td><b>sum</b></td><td><b>sum</b></td><td><b>sum</b></td><td><b>sum/b></td><td><b>sum</b></td><td></td></tr>"; 

但我不知道該怎麼做。請幫忙。謝謝。

+1

[**在新的代碼,請不要使用'mysql_ *'功能**](http://bit.ly/phpmsql )。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。 – Kermit

+0

注意。謝謝。 – xjshiya

回答

0

你可以做這樣的事情:

$sum = 0; 
while($b=mysql_fetch_array($a)) 
{ 
    //your codes 

    $sum += $fields //fields you want to sum up 

    echo "<tr><td> 'Sum:'. $sum ... </td></tr>"; 
} 

echo "</table>"; 

+0

upvote它也pls? :d –