【问题标题】:sum all columns in php mysql对php mysql中的所有列求和
【发布时间】:2017-03-26 20:26:19
【问题描述】:
CREATE TABLE onecanteen (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Items_wholesale CHAR(30) NOT NULL,
Items_retail CHAR(30) NOT NULL,
Ammount_recive CHAR(30) NOT NULL,
items_quantity Char(30)NOt Null,
)

插入数据:

<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-save']))
{
    $wholesale = $_POST['Items_wholesale'];
    $retail = $_POST['Items_retail'];
    $quantity = $_POST['items_quantity'];
    $recive = $_POST['Ammount_recive'];

    if($crud->create($wholesale,$retail,$quantity,$recive))
    {
        header("Location: add-data.php?inserted");
    }
    else
    {
        header("Location: add-data.php?failure");
    }
}
?>

php初学者 创建/读取/更新/删除 通常数据存储在 MySQL 数据库中 存储数据后,我在获取数据时执行下面提到的数学运算

<td>            <?php print($row['id']); ?></td>
                <td><?php print($row['Items_wholesale']); ?></td>
                <td><?php print($row['Items_retail']); ?></td>
                <td><?php print($row['items_quantity']); ?></td>
                <td><?php print($row['Ammount_recive']); ?></td>
                <td><?php echo $row['Items_retail'] * $row['items_quantity'] ?></td>
                <td><?php echo $row['Items_wholesale'] * $row['items_quantity'] ?></td>
                <td><?php echo ($row['Items_retail'] * $row['items_quantity'] )-($row['Items_wholesale'] * $row['items_quantity'])  ?></td>

在这里我看到了我所有的记录

<!-- showing whole record add delet record  -->
<div class="clearfix"></div>

<div class="container">
<a href="add-data.php" class="btn btn-large btn-info"><i class="glyphicon glyphicon-plus"></i> &nbsp; Add Records</a>
</div>

<div class="clearfix"></div><br />

<div class="container">
     <table id="table1" class='table table-bordered table-responsive'>
     <tr>
     <th >#</th>
     <th >Wholesale</th>
     <th >retail</th>
     <th >Quantity</th>
     <th >wholesale total</th>
     <th >Retail total</th>
     <th >profit</th>
     <th >Recive ammount </th>
     <th colspan="2" align="center">Actions</th>


     <?php
        $query = "SELECT * FROM onecanteen";
        $records_per_page=3;
        $newquery = $crud->paging($query,$records_per_page);
        $crud->dataview($newquery);
     ?>
    <tr>

程序完美地从 onecanteen 表中获取数据 现在我想总结所有列 hlpe 我该怎么做??

【问题讨论】:

  • 对所有列求和?你的意思是什么,列数据是什么?你只能对数字求和。你能解释一下你试图通过那个“SUM”实现什么吗?
  • 所有输入都是数字
  • 结果应该是什么?每列分开?还是一起?
  • 是的!每列单独总计..

标签: php mysql


【解决方案1】:

要分别计算每列中的数据总量,您可以使用:

SELECT SUM(column_name) as sum1, SUM(column_name1) as sum2 FROM ....

【讨论】:

  • 我修改了我的问题希望你现在能更好地理解它
猜你喜欢
  • 1970-01-01
  • 2020-12-02
  • 2015-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-17
  • 2014-05-12
相关资源
最近更新 更多