I am using an HtML and PHP. I have to check the Table with the If condition using PHP for Example
<?php if($status==0) {?>
<td><input type='text' name='test' id='test' value=''>
<?php }?>
<?php else (if($status==2) && ($status==1)) {?>
<td><input type='text' name='test' id='test' value=''>
<?php }?>
Am getting eror a开发者_如何学JAVAs unexpected else and unexpected boolean.........
Is it wrong?
Looking at your code, it seems you have two syntax errors.
First, the following lines :
<?php } ?>
<?php else (if($status==2) && ($status==1)) { ?>
Should go in only one PHP tag : there should be no closing + beginning tags between the }
and the else
.
Second, the opening parenthesis should not be between the else
and the if
-- but arround the condition :
<?php } else if(($status==2) && ($status==1)) { ?>
While the others have covered your syntax error, I'll cover your logic error:
<?php } else if(($status==2) && ($status==1)) { ?>
This checks to see if $status
is equal to 2, and then also checks that $status
is equal to 1.
$status
can't be both 1 and 2 at the same time.
If $status
is 1, then the if
check evaluates to:
<?php } else if((false) && (true)) { ?>
... which is false
, meaning the condition won't match.
You probably want ||
, the "logical or" operator instead of &&
, the "logical and" operator:
<?php } else if(($status==2) || ($status==1)) { ?>
Here's the PHP manual page on logical operators.
you have syntax error while saying else if.... I would rewrite the code as following:
<?php if($status==0) :?>
<td><input type='text' name='test' id='test' value=''>
<?php else if (($status==2) && ($status==1)) :?>
<td><input type='text' name='test' id='test' value=''>
<?php endif; ?>
Here is syntax error
<?php else (if($status==2) && ($status==1)) {?>
Change it to
<?php elseif(($status==2) && ($status==1)) {?>
EDIT
Space is not allowed between elseif. Also you have logical error as others pointed change your &&
to ||
Note: Note that elseif and else if will only be considered exactly the same when using curly brackets When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.
<?php if ($vCertificateStatus==0):?>
<td><input type="text" name="CertificateDate" id="CertificateDate" value="" />
<?php elseif(($vCertificateStatus==-1) || ($vCertificateStatus==1)):?>
<td><input type="text" name="CertificateDate" id="CertificateDate" value="<?php echo $vReceivedDate;?>" />
<?php endif; ?>
Insteed of {...} you need to use : and endif;
<?php if($status==0) :?>
<td><input type='text' name='test' id='test' value=''>
<?php elseif(($status==2) && ($status==1)) :?>
<td><input type='text' name='test' id='test' value=''>
<?php endif; ?>
?>
精彩评论