I am trying to echo some text depending on the results of a timestamp, using an if/else statement.
My logic is as follows;
Based on the value of $data;
- If no results => echo 'no results'
- If date is less than todays date => echo 'expired'
- Else => echo 'active'
The problem I am facing is that currently my code always displays 'active' no matter what the date is - my code so far is;
<?php
$data = get_patronapi_data($id);
$dataTimestamp = strtotime($data);
$now = strtotime('today');
//echo strtotime('now'); this outputs 1446820684
//echo $dataTimestamp; this outputs 1954886400
//echo $data; this outputs 31-12-13
//if $data is empty
if (empty($data)){
echo 'no results';
}
//if $data is not empty but date is less than today
elseif (!empty($data) && $dataTimestamp < $now) {
echo 'expired';
}
//everything else
else {
echo 'active';
}
?>
I'm sure the answer will be obvious to a pro but you have a newbie here!
Aucun commentaire:
Enregistrer un commentaire