gpt4 book ai didi

PHP Sum Of Mysql 行值

转载 作者:太空宇宙 更新时间:2023-11-03 12:15:57 25 4
gpt4 key购买 nike

figure 1. sum all value of money   
id date name money //sample items only
1 March 5 2014 matt 50 //records to add
2 March 5 2014 john 10 //records to add
3 March 2 2014 matt 50 //records to add

figure 2. sum all value of money when search matt
id date name money //sample items only
1 March 5 2014 matt 50 //records to add
2 March 5 2014 john 10
3 March 2 2014 matt 50 //records to add

大家好,你能帮帮我吗?我不知道如何在我的 sql 数据库中添加行值的代码。(参见上面的示例)

我有这段代码可以计算我有多少条记录

<input type="text" name="namesearch" size="5"  tabindex="1" />

<input type="submit" name='click' value='Search' />


if(isset($_POST['click'])){


$name= $_POST['namesearch'];
$query = "SELECT COUNT(*) AS total FROM table WHERE name='$name'";
$result = mysql_query($query);
$values = mysql_fetch_assoc($result);
$num_item= $values['total'];
echo "Number of Records Found # ".$num_item;

最佳答案

将其用作查询

$query = "SELECT COUNT(*) AS total, SUM(money) AS total_money FROM table WHERE name='$name'"; 

使用这个查看结果

$num_item = $values['total']; 
$total_value = $values['total_money'];
echo "Number of Records Found # ".$num_item;
echo "Total Money ".$total_value

关于PHP Sum Of Mysql 行值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22190494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com