2013-05-22 2 views
0

나는 reservationpostflight 테이블을 가지고 있습니다. reservation 테이블에서 쿼리를 수행하고 postflight 테이블의 데이터를 찾아야합니다. 나는 </table>을 닫기 전에요약 결과 쿼리

$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>"; 
    } 

} 

는, 나는 위의 쿼리의 출력 데이터를 기반으로 요약 될 모든 필수 필드를 요약 어디 다른 행을 추가하고 싶습니다. 예 :

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)를 참조하십시오. 대신 [* prepared statements *] (http://j.mp/T9hLWi)에 대해 알아보고 [PDO] (http://php.net/pdo) 또는 [MySQLi] (http://php.net/)를 사용하십시오. mysqli) - [이 기사] (http://j.mp/QEx8IB)는 어떤 결정을 내리는 데 도움이 될 것입니다. – Kermit

+0

Noted. 고맙습니다. – 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? :디 –