gpt4 book ai didi

php - 如何检查Mysql时间字段是否为NULL

转载 作者:行者123 更新时间:2023-11-29 06:44:24 25 4
gpt4 key购买 nike

我是编程新手,正在尝试使时间表发挥作用。我的问题是,无论我尝试什么,我都无法让 PHP 检查 endWork 上的数据库中的值是否已设置或为 NULL。 (目前为空)

<?php
if (isset($_POST['setTimestamp'])) {
$date = $_POST['date'];
$workDate = date('Y-m-d');


$dateQuery = "SELECT WorkDate FROM WorkingHours WHERE WorkDate =
'$workDate'";
$eWorkQuery = "SELECT EndWork FROM WorkingHours WHERE WorkDate =
'$workDate'";
$eBreakQuery = "SELECT EndBreak FROM WorkingHours WHERE WorkDate =
'$workDate'";
$sBreakQuery = "SELECT StartBreak FROM WorkingHours WHERE WorkDate =
'$workDate'";
$sWorkQuery = "SELECT StartWork FROM WorkingHours WHERE WorkDate =
'$workDate'";


$d_query_run = mysqli_query($con, $dateQuery);
$e_w_query_run = mysqli_query($con, $eWorkQuery);
$e_b_query_run = mysqli_query($con, $eBreakQuery);
$s_b_query_run = mysqli_query($con, $sBreakQuery);
$s_w_query_run = mysqli_query($con, $sWorkQuery);


if (mysqli_num_rows($d_query_run)==1) {

if (!isset($e_w_query_run)) {

if (empty($e_b_query_run)) {

if (empty($s_b_query_run)) {

if (empty($s_w_query_run)) {
}
else{
echo " set StartBreak's time to localtime ";
}


}
else{
echo " set EndBreak's time to localtime ";
}


}
else{
echo " set EndWork's time to localtime ";
}


}

else{
echo " You already submited your timesheet for today ";
echo "<pre>" ,print_r($e_w_query_run, TRUE),"</pre>";
}


}
else{
echo " set StartWork's time to localtime";
}

}
?>

下面的代码行仅用于检查查询的输出。

echo "<pre>" ,print_r($e_w_query_run, TRUE),"</pre>";

我已经尝试过 !isset() is_null empty() 。大多数情况下,它告诉我它不能在对象上使用这些操作,而是在数组上使用。因此,我尝试了 mysqli_fetch_array但这也不起作用。

如果有人能帮助我解决这个问题,那就太好了,并且提前致谢。

最佳答案

仅运行mysqli_query不会为您提供数据。为了访问它,您需要执行以下操作:

$qyery = mysqli_query($con, $eWorkQuery);
$result = mysqli_fetch_array($query);
if(is_null($result['EndWork'])){
echo " set EndBreak's time to localtime ";
}

或者如果你想使用对象

$result = mysqli_fetch_object($query);
if(is_null($result->EndWork)){
echo " set EndBreak's time to localtime ";
}

关于php - 如何检查Mysql时间字段是否为NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50151590/

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