无法从PHP中的MySQL获取总和结果

时间:2019-01-21 05:31:22

标签: php mysql

这是我的PHP代码,其中包括MySQL数据库。在MySQL数据库中,有一列“金额”,另一列是“日期”。我想对两个日期之间的金额列求和。但是我无法得到结果。请帮帮我。

<?Php
error_reporting(0);
include "config_1.php";
echo "<form  method=post action='getcollectionbagnan.php' ><input type=hidden  name=todo value=search>
<input type=date  name=search_text value='$search_text' ><br>
<input type=hidden  name=todo2 value=search2>
<input type=date  name=search_text2 value='$search_text2' ><input type=submit value=Search><br>
</form>
";
$todo=$_POST['todo'];
$search_text=$_POST['search_text'];
$todo2=$_POST['todo2'];
$search_text2=$_POST['search_text2'];
if(isset($todo) and $todo=="search" and isset($todo2) and $todo2=="search2"){
$type=$_POST['type'];
$search_text=ltrim($search_text);
$search_text=rtrim($search_text);
$search_text2=ltrim($search_text2);
$search_text2=rtrim($search_text2);
if($type<>"any"){
$query="select sum(amount) from billbagnan where date between $search_text and $search_text2 ";
$count=$dbo->prepare($query);
$count->execute();
$sumAmount = 0;
while($row = $count->fetch()) {
    $sumAmount = $row[0];
}
echo $sumAmount;
}
}
?>

0 个答案:

没有答案