gpt4 book ai didi

PHP 从 MySQL 获取本周数据

转载 作者:行者123 更新时间:2023-11-29 04:40:14 25 4
gpt4 key购买 nike

下面的 PHP 代码在当前日期工作正常,可以从 MySQL 获取数据以获取定义的特定 ID 的出勤率。我需要它来获取当前的一周和一个月。我用谷歌搜索了很多但无法解决。小小的帮助将不胜感激。

如果有可能使用 JavaScript 的方法,请告诉我。

// SELECT Time Zone
date_default_timezone_set("Europe/Belfast");

// SELECT Date With Default Time i.e "00:00:00"

$date= date("y-m-d 00:00:00");

$mysqli=mysqli_connect('localhost','Uid','PASS','DB');

//Passed From Ajax
$Fetch_date = $_POST['ID'];

// Example Date is 2015-06-18 00:00:00 And id is 12345
$query ="SELECT * FROM attendance WHERE RegID='$Fetch_date' And Date='$date' ";

$result = mysqli_query($mysqli,$query)or die(mysqli_error());

$num_row = mysqli_num_rows($result);

while($row=mysqli_fetch_array($result))
{
//Echo result hear Working Fine
}

最佳答案

本月:

$date1 = date('Y-m-01 00:00:00');
$date2 = date('Y-m-d 23:59:59', strtotime('last day of this month'));

$sql = "select * from attendance where RegID='$Fetch_date' and Date > '$date1' and Date < '$date2' ";

本周:

$date1 = date('Y-m-d 00:00:00', strtotime('monday this week'));
$date2 = date('Y-m-d 23:59:59', strtotime('sunday this week'));

$sql = "select * from attendance where RegID='$Fetch_date' and Date > '$date1' and Date < '$date2' ";

P.S.:此题与javascript无关

关于PHP 从 MySQL 获取本周数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30703872/

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