如何检查mysql时间字段是否为空

yhived7q  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(394)

我对编程还不熟悉,正努力让时间表工作。我的问题是,无论我尝试什么,我都无法让我的php检查我的db on endwork中的值是set还是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 但这也不管用。
如果有人能帮我解决这个问题,那就太棒了,还要提前感谢。

ipakzgxi

ipakzgxi1#

只是跑步 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 "; 
}

相关问题