简体   繁体   中英

How to put condition inside the echo statement?

I have this while loop inside a php statement. Inside my while loop i put echo and inside that echo is a td tag. After it is another if condition with img src determining from a row inside it and another echo with br and td tag in it. How can I resolve this?

Here is my code

while($row = $result->fetch_assoc()){
                        echo '<tr>
                            <!--Photos first-->
                            <td><center>s';
                            if(!empty(trim($row['photo']))){
                                    echo "<img src='.$row['photo'].' class='img-circle' height='100px' width='100px'> ";
                                    echo '<br>.$row["username"]. <br></td>';
                            }
                    }  

Error that showed

unexpected $EOF, expecting TSTRINg TVARIABLE T NUM STRING

You are not escaping ' properly, try this :

while($row = $result->fetch_assoc()){
    echo '<tr>
    <!--Photos first-->
    <td><center>';
    if(!empty(trim($row['photo']))){
        echo "<img src='" . $row['photo'] . "' class='img-circle' height='100px' width='100px'> ";
        echo '<br>' .$row["username"]. '<br></td>';
    }
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM