作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只是想知道如何在 SQL 中获取列的值,当选中该复选框时,它会将这些值相加,因为它们是数字。
数据
表名=添加
SEARCH = Dan
-----------------------
name | date | Total | Checkbox
-------------------------------------
Dan | dd/mm/yyy | 200 | checked
Dan | dd/mm/yyy | 400 | checked
Dan | dd/mm/yyy | 300 | checked
Dan | dd/mm/yyy | 250 | unchecked
Dan | dd/mm/yyy | 260 | unchecked
TOTAL AMOUNT = 900
更新:这是我到目前为止所做的代码,但它仍然无法工作。
<?php
include "connection.php";
//$searchName= $_POST['submit'];
if(isset($_POST['submit'])){
$searchName = $_POST['submit'];
$searchName = preg_replace("#[^0-9a-z]#i","",$searchName);
$query = "SELECT * FROM adding where Code LIKE '$searchName%' ORDER BY Date";
$result = mysql_query($query);
if(mysql_num_rows($result)>0){
echo "<form action=Payment.php method=get>";
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Date</th>
<th>Total</th>
<th>Checkbox</th>
</tr>";
while($row = mysql_fetch_array($result)){
//$idno = $row['id'];
echo "<tr>";
echo "<td>" . $row['Code'] . " </td>";
echo "<td>" . $row['Date'] . "</td>";
echo "<td>" . $row['Total'] . "</td>";
echo "<td><input type = \"checkbox\" name=\"pay[]\" value='{$row['id']}' ></td>";
echo "</form>";
}
echo "<table>";
echo "<input type=\"submit\" name =\"button2\" value=\"Submit\">";
echo "</form>";
if(isset($_GET['pay'])){
$checked=$_GET("pay");
$c= count($checked);
$totalpayment = $row['Total'];
for($i=0;$i<$c;$i++){
if($checked[$i]==$row['id']){
$totalpayment = $totalpayment+$row['Total'];
}
}
echo "total is: " .$totalpayment. "<br>";
}
}
else{
echo "RECORD NOT FOUND!";
}
}
mysql_free_result($result);
?>
最佳答案
试试这个
select sum(total) as TOTAL AMOUNT from table
where Checkbox='checked'
关于php sql 在选中复选框时获取查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44129418/
我是一名优秀的程序员,十分优秀!