Reputation: 1860
I've been struggling with this from yesterday. I'm trying to do an if statement in an echo, I've followed this post (if block inside echo statement?) but my if statement does not evaluate to true. I've even put in the values for $quenr1 & $anscho1 but no sucess. Please help. Please reply if you need all the code.
$quenr1 = 1;
$anscho1 = 'A';
if ($q_type != 'mr')
{
if($option1!="")
{
echo "<input type='radio' name='$quenr1' value='A'" . ($anscho1 == A ? 'checked="checked"' : '') . ">$quenr1<br />";
}
}
EDITED
Thanks for all the replies, you've put me in the right direction. As a last resort I removed all my code and started from scratch and just put in the query to retrieve the data and display the form and it worked fine.
Upvotes: 1
Views: 5720
Reputation: 1330
echo "<input type='radio' name='$quenr1' value='A'".(($anscho1 == 'A')? ' checked="checked"' : '').">$quenr1<BR>";
right put () arround your condition and '' around the A
Upvotes: 4
Reputation: 10583
Try this
echo "<input type='radio' name='$quenr1' value='A'" .
(($anscho1 == 'A') ? 'checked="checked"' : '')
. ">$quenr1<BR>";
Put ()
around your condition.
Upvotes: 4