jarv Posted May 29, 2013 Share Posted May 29, 2013 Please help, I get the following php error: unexpected T_IF here is my code: echo '<input type="radio" name="BGimageID" value="'.$row2['BGimageID'].'" '.if($row2['pages.BGimageID']==$row2['bgimages.BGimageID']){ echo " checked" }' /><img src="../images/'.$row2['BGimage'].'" width="150" />'; Quote Link to comment Share on other sites More sharing options...
dannon Posted May 29, 2013 Share Posted May 29, 2013 (edited) Please help, I get the following php error: unexpected T_IF here is my code: echo '<input type="radio" name="BGimageID" value="'.$row2['BGimageID'].'" '.if($row2['pages.BGimageID']==$row2['bgimages.BGimageID']){ echo " checked" }' /><img src="../images/'.$row2['BGimage'].'" width="150" />'; You cannot use the 'if' keyword in the middle of functions or variable assignments. Take a look at this http://www.php.net/manual/en/language.expressions.php Sorry for horrible wording. Edited May 29, 2013 by dannon Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 29, 2013 Share Posted May 29, 2013 As Dannon pointed out, you can not concatenate a string onto a language construct (in this case your if statement). However, since your goal is output html in this section of code, I'd recommend that you utilize PHP's ability to intermix html and php code. <?php // prior code here // Now end php block ?> <input type="radio" name="BGimageID" value="<?= $row2['BGimageID'] ?>" <?= $row2['pages.BGimageID'] == $row2['bgimages.BGimageID'] ? ' checked' : ''; ?> /> <img src="../images/<?= $row2['BGimage'] ?>" width="150" /> <?php //More php code if needed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.