Jump to content

[SOLVED] Else/If Help


Clinton

Recommended Posts

This is the original code:

 

$kuccpitexpire = strtotime($kuccpit.'+ 12 months');

$kuccpitexpire = date('n/j/Y',$kuccpitexpire);

$kuccpit = strtotime($kuccpit.'+ 11 months');

$kuccpit = date('Y-m-d',$kuccpit);

if ($nowtrue > $kuccpit) {
echo "
$fname $lname is due for the KUCC Hazard Recognition Precious Metals Program! It Expires $kuccpitexpire
";
}

 

Now, I am trying to add an If statement to the begining of it, a couple of different ways, and I can't figure it out. This is what I have currently:

 

if ($row{'kuccpit'}=='0000-00-00') echo " ";

else

$kuccpitexpire = strtotime($kuccpit.'+ 12 months');

$kuccpitexpire = date('n/j/Y',$kuccpitexpire);

$kuccpit = strtotime($kuccpit.'+ 11 months');

$kuccpit = date('Y-m-d',$kuccpit);

($nowtrue > $kuccpit) {
echo "<center> $fname $lname is due for the KUCC Pit License! It Expires $kuccpitexpire <p></center>";
}

Link to comment
Share on other sites

i think this should work  ... not tested

 

<?php if ($row{'kuccpit'}=='0000-00-00'){ echo " ";}
else
{

$kuccpitexpire = strtotime($kuccpit.'+ 12 months');

$kuccpitexpire = date('n/j/Y',$kuccpitexpire);

$kuccpit = strtotime($kuccpit.'+ 11 months');

$kuccpit = date('Y-m-d',$kuccpit);

if ($nowtrue > $kuccpit) {
echo "
$fname $lname is due for the KUCC Hazard Recognition Precious Metals Program! It Expires $kuccpitexpire
";
}} ?>

Link to comment
Share on other sites

The only time you don't need to use curly braces on conditional statements if when there's only 1 evaluation/function to be performed within that condition. Examples below

 

<?php

$bool = FALSE;

if ( $bool = TRUE )
echo 'This will work fine, but will not be outputted';
else
echo 'This will work fine, and will be outputted';

if ( $bool = FALSE )
echo 'This will work fine, and will be outputted';
else
echo 'This will work fine, but will not be outputted';
echo 'This will work fine, and will be outputted, because the
      else statement ended after the above echo';

if ( $bool = TRUE )
echo 'This will work fine, but will not be outputted';
echo 'This will break ths script, because the if statement ended
      after the above echo, so the else below will not have a
      corresponding if statment';
else
echo 'This would work, but the above broke the script';

if ( $bool = TRUE ) {
echo 'This will work fine, but will not be outputted';
echo 'This will also work fine because it is within the if\'s curley brace';
} else
echo 'This will work fine, and will be outputted';

# Alternately

if ( $bool = TRUE )
echo 'This will work fine, and will be outputted';
else {
echo 'This will work fine, but will not be outputted';
echo 'This will also work fine because it is within the if\'s curley brace';
}

?>

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.