如何显示 2 个不同日期范围的数据

我有以下数据,用于显示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


慕田峪9158850
浏览 52回答 1
1回答

波斯汪

您应该在此处使用预准备语句,并且还使用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();
打开App,查看更多内容
随时随地看视频慕课网APP