Jump to content

[SOLVED] elseif


richiec

Recommended Posts

if(strtotime('now') > strtotime("{$date}")) {
      echo "something when strtotime > than just the date";   

}

elseif(strtotime('now') > strtotime("{$date $time}")) {
      echo "something when strtotime > date and time";

} else {
      echo "defult for if strtotime < now";
}

 

Can anyone see what is wrong with this? I am guessing it is getting confused because if strtotime > date it echos something but if strtotime > date and time it echos something else... any ideas? =\

Link to comment
Share on other sites

try

 

<?php

if(strtotime('now') > strtotime("{$date}")) {
      echo "something when strtotime > than just the date";   

}

elseif(strtotime('now') > strtotime($date . $time)) {
      echo "something when strtotime > date and time";

} else {
      echo "defult for if strtotime < now";
}

?>

Link to comment
Share on other sites

Try:

<?php
$now = time();
echo 'now = ' . $now . '<br>';
echo 'date = ' . $date . '<br>';
echo 'time = ' . $time . '<br>';
switch (true) {
case ($now  > strtotime($date)):
      echo "something when strtotime > than just the date";   
      break;
case (strtotime('now') > strtotime($date . ' ' . $time)):
      echo "something when strtotime > date and time";
      break;
default:
      echo "default for if strtotime < now";
}
?>

 

Ken

Link to comment
Share on other sites

Well, the first comparison is satisfied so, it stops looking. Switch the order of the checks:

<?php
$now = time();
echo 'now = ' . $now . '<br>';
echo 'date = ' . $date . '<br>';
echo 'time = ' . $time . '<br>';
switch (true) {
case (strtotime('now') > strtotime($date . ' ' . $time)):
      echo "something when strtotime > date and time";
      break;
case ($now  > strtotime($date)):
      echo "something when strtotime > than just the date";   
      break;
default:
      echo "default for if strtotime < now";
}
?>

 

Ken

Link to comment
Share on other sites

bumping sorry, but i still cant get this to work right so im going to post the whole secton of code so you can maybe see more of what i am trying to do...


<?php
$now = putenv("TZ=America/New_York");
$currentdate = date('n-j-Y');
$datentime = date('n-j-Y',strtotime('now'));
$name = mysql_result($result,$i,"name");
$date = mysql_result($result,$i,"date");
$time =mysql_result($result,$i,"time");
$respawn =mysql_result($result,$i,"respawn");
$image =mysql_result($result,$i,"image");
$image2 =mysql_result($result,$i,"image2");
$image3 =mysql_result($result,$i,"image3");
$update =mysql_result($result,$i,"update");

switch (true) {

case ($date > $currentdate):
      echo "<img onMouseOut=\"kill();\" onMouseOver=\"popup('<font color=\'#FFFFFF\'><b>$name - Level $level<br>($respawn)<br><br></font>$area<br><br><font color=\'#FF0000\'>Not Due Yet</font><br><br><font color=\'#FFFFFF\'>Due On $date <br> (Day-Month-Year)<br><br>At $time <br> (24 Hour Clock)<br><br>Updated by $update</font>');\" src=\"$image2\" alt=\"\" width=\"75\" height=\"75\">";
      break;
case ($now > $datentime):
      echo "<img onMouseOut=\"kill();\" onMouseOver=\"popup('<font color=\'#FFFFFF\'><b>$name - Level $level<br>($respawn)<br><br></font>$area<br><br><font color=\'#00FF33\'><b>Due Now!</b></font><br><br><font color=\'#FFFFFF\'>Started on $date <br> (Day-Month-Year)<br><br>At $time <br> (24 Hour Clock)<br><br>Updated by $update</font>');\" src=\"$image\" alt=\"\" width=\"75\" height=\"75\">";
      break;

default:
      echo "<img onMouseOut=\"kill();\" onMouseOver=\"popup('<font color=\'#FFFFFF\'><b>$name - Level $level<br>($respawn)<br><br></font>$area<br><br><font color=\'#FFFF00\'><font size=\'2\'>Due Today!</font></font><font color=\'#FFFFFF\'><br><br>At $time <br> (24 Hour Clock)<br><br>Updated by $update</font>');\" src=\"$image3\" alt=\"\" width=\"75\" height=\"75\">";
}
?>

Ok what it is doing, the defult seems to work and $date > $currentdate seems to work however... when $now > $datentime it still displays the defult.. any ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.