Page 1 of 1
Break out of echo ..
Posted: Sun Apr 22, 2007 8:57 pm
by bob_the _builder
Hi,
Is there away to break out of an echo statment without having to close off ie:
Code: Select all
<td><input name="first" type="text" value="'.$first.'"> '.( if(!$first){ ' *'; } ).'</td>
Thanks
Posted: Sun Apr 22, 2007 9:08 pm
by John Cartwright
What?
Posted: Sun Apr 22, 2007 9:14 pm
by bob_the _builder
If you have something like:
echo '<td><input name="first" type="text" value="'.$first.'"></td>';
and you want to error check fields using:
if(!$first){ echo ' *'; }
is there a way to place the whole lot within:
echo ' ';
without having to use the likes of:
Code: Select all
echo '<td><input name="first" type="text" value="'.$first.'"></td>';
if(!$first){ echo ' *'; }
echo '<td><input name="last" type="text" value="'.$last.'"></td>';
if(!$last){ echo ' *'; }
Thanks
Posted: Sun Apr 22, 2007 9:27 pm
by Christopher
Like:
Code: Select all
echo '<td><input name="first" type="text" value="'.($first ? $first : '*').'"></td>';
echo '<td><input name="last" type="text" value="'.($last ? $last : '*').'"></td>';
Posted: Sun Apr 22, 2007 9:29 pm
by John Cartwright
Ah, your looking for the
ternary operator.
Edit | A bit late.. left window open and forgot about it

Posted: Sun Apr 22, 2007 9:42 pm
by bob_the _builder
Perfect ..
Thanks
Posted: Mon Apr 23, 2007 12:14 am
by bob_the _builder
Hi,
Im using:
Code: Select all
<td><input name="first" type="text" value="'.$first.'">'.($first ? '' : ' *').'</td>
To display * outside of the text field.
Thanks .. cleans my code up nicely