PHP / MySql - determining the date when values ​​were assigned?

I want to make an if statement that works only if the datetime value is not null (0000-00-00 00:00:00)

I passed the value through the request to a variable, but how to determine if it is equal 0000-00-00 00:00:00?

$query = "SELECT * FROM stats WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "' "; 
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
  $money = $row['money'];
  $bank_money = $row['bank_money'];
  $ap = $row['ap'];
  $exp = $row['exp']; 
  $last_ap_update = $row['last_ap_update'];
} 

if ($last_ap_update != ){ //Can i verify its NULL-ness here so i can run this if stament or run else?
}
+3
source share
5 answers

Why not directly compare it:

if ($last_ap_update != "0000-00-00 00:00:00")
{
      //do whatever.
}
+5
source

You store it in a variable to use it as a string

if ($last_ap_update != "0000-00-00 00:00:00"){
}
+1
source
if ($last_ap_update != "0000-00-00 00:00:00"){
    [process]
}
+1

$last_ap_update != strtotime("0000-00-00 00:00:00")

0

SQL-?

$query = "SELECT * FROM stats WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "' AND  last_ap_update > 0";

, > 0, <> '0000-00-00 00:00:00', .

0

Source: https://habr.com/ru/post/1762448/


All Articles