Link to home
Start Free TrialLog in
Avatar of bschwarting
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>";

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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...
Avatar of bschwarting
bschwarting

ASKER

true, i guess i can do before
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Julian Hansen
This is a good case for using a Ternary expression

$onemonthahead = $date_type == 'NEW' ? 'NEWCONTRACT' : '';

Open in new window


This is equivalent to
if ($data_type == 'NEW') {
  $onemonthahead='NEWCONTRACT';
}
else {
  $onemonthahead= '';
}

Open in new window