显示最后一列的总和

时间:2015-10-19 07:08:00

标签: php mysql

  •   

    波兰钻石   信息

    mysql_connect("localhost","root",""); mysql_select_db("basic");
    
    $order = "select * from polish ";       $result=mysql_query($order);
    
    
    $a="select sum(total) from polish"; $b=mysql_query($a);
    
    
     ?>
    <?php echo "Polish Diamonds Information: &nbsp; &nbsp; &nbsp; &nbsp; ";
          echo "<a href='home.html'>Go to main page
          <br><br>";
    
    ?>
    
    
    
    <table border="1" style="width:50%">
    
             <tr>
                <th><b>ID</b></th>
                <th><b> Name</b></th>
                <th> <b>Selection</b><br>(40000)</th>
                <th><b>Super Deluxe<br>(35000)</b></th>
                <th><b>1<br>(30000)</b></th>
                <th><b>2<br>(25000)</b></th>
                <th><b>3<br>(20000)</b></th>
                <th><b>4<br>(10000)</b></th>
                <th><b>Total Payment</b></th>
                <th><b>Days</b></th>
    
                     </tr>
    
    
    
        <?php        while($row = mysql_fetch_array($result) )       {
            echo "<tr>
                <td>".$row['id']."</td>
                <td>".$row['name']."</td>
                <td>".$row['c_sel']."</td>
                <td>".$row['c_sdel']."</td>
                <td>".$row['c_1']."</td>
                <td>".$row['c_2']."</td>
                <td>".$row['c_3']."</td>
                <td>".$row['c_4']."</td>
                <td>".$row['total']."</td>
                <td>".$row['day']."</td>
             </tr>";         }
    
    ?>    </html>
    

2 个答案:

答案 0 :(得分:0)

试试这个循环

$sum_val=0;
while($row = mysql_fetch_array($result) )       {
    echo "<tr>
        <td>".$row['id']."</td>
        <td>".$row['name']."</td>
        <td>".$row['c_sel']."</td>
        <td>".$row['c_sdel']."</td>
        <td>".$row['c_1']."</td>
        <td>".$row['c_2']."</td>
        <td>".$row['c_3']."</td>
        <td>".$row['c_4']."</td>
        <td>".$row['total']."</td>
        <td>".$row['day']."</td>
     </tr>";
     $sum_val+=$row['total'];
     }

     echo"Last column total= $sum_val";

答案 1 :(得分:0)

你通过这种方式试试

$order = "select *, sum(c_sel+c_sdel+c_1+c_2+c_3+c_4) as total from polish GROUP BY id "; $result=mysql_query($order);