bschwarting
asked on
php mysql if then statement syntax
How do I check in an echo statement if $data_type = NEW then $onemonthahead = NEWCONTRACT
echo "<td colspan='3' valign='top' align='center' class='paramText'><input class='rateTextbox' type='text' id='cont_strt' name='cont_strt' maxlength='10' size='10'
autocomplete='off' required value=$onemonthahead'> (MMDDYY)</td>";
You don't usually do this in an echo statement. The best way would be to write the conditional statements separately. I'll see if I can give you an example...
ASKER
true, i guess i can do before
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is a good case for using a Ternary expression
This is equivalent to
$onemonthahead = $date_type == 'NEW' ? 'NEWCONTRACT' : '';
This is equivalent to
if ($data_type == 'NEW') {
$onemonthahead='NEWCONTRACT';
}
else {
$onemonthahead= '';
}