我有以下数据,用于显示MySQL数据参数date$tgaw=date("Y-m-10");$tgak=date("Y-m-09", strtotime("+1 months"));我有以下查询:$querylembur = "SELECT SUM(total) as subtotal FROM lembur WHERE tgl between ".$tgaw." AND ".$tgak." AND staff =".$row['nama'];$rslembur=mysqli_query($con,$querylembur);$rowlembur=mysqli_fetch_array($rslembur);我想要的结果是程序将显示从日期到现在的数据::$tgaw$tgak
1 回答
波斯汪
TA贡献1811条经验 获得超4个赞
您应该在此处使用预准备语句,并且还使用MySQL函数将一个月添加到该范围内的上限日期。
$sql = "SELECT SUM(total) AS subtotal FROM lembur WHERE tgl BETWEEN ? AND DATE_ADD(?, INTERVAL 1 MONTH) AND staff = ?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("sss", $tgaw, $tgaw, $row['nama']);
$stmt->execute();
// fetch here
$stmt->close();
- 1 回答
- 0 关注
- 51 浏览
添加回答
举报
0/150
提交
取消