Jump to content

unexpected T_IF


jarv

Recommended Posts

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" />';
Link to comment
Share on other sites

 

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 by dannon
Link to comment
Share on other sites

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
 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.