K.Wayne K.Wayne - 5 months ago 16
HTML Question

How to echo the image inside HTML and php?

How to echo the image

if(isset($post->foto)
inside the code below? I am trying with the below code but I can't find any solution. Its returning the following error


Parse error: syntax error, unexpected 'userdata' (T_STRING), expecting
',' or ';'.


foreach($postimet as $post){
$firstname = $user->getUserById($post->userid)['first'];
$lastname = $user->getUserById($post->userid)['last'];
foreach($fotos as $foto){
echo
"<div class='po_001'>
<div class='po_004'>
<img src='timeline/".$foto."' class='po_003'>
<div class='po_005'>
<a href='profile.php' class='po_002'>$firstname $lastname</a>
</div>
<div class='po_006'>
<span class='p_007'>$post->posttime</span>
</div>
</div>
<div class='po_008'>
<p class='po_009'>$post->message</p>
</div>
<div class='po_010'>
if(isset($post->foto))
{
<img class='myimage'src='"userdata/".$post->foto->imagename."'>
}
</div>
</div>";
}
}

Answer

You need to do it like below:-

<?php
foreach($postimet as $post){
    $firstname = $user->getUserById($post->userid)['first'];
    $lastname = $user->getUserById($post->userid)['last'];
    foreach($fotos as $foto){?>
        <div class='po_001'>
            <div class='po_004'>
                <img src="timeline/<?php echo $foto;?>" class='po_003'>
                <div class='po_005'>
                    <a href='profile.php' class='po_002'>$firstname $lastname</a>
                </div>
                <div class='po_006'>
                    <span class='p_007'>$post->posttime</span>
                </div>
            </div>
            <div class='po_008'>
                <p class='po_009'>$post->message</p>
            </div>
            <div class='po_010'>
            <?php if(isset($post->foto)){?>
                <img class='myimage'src="userdata/<?php echo $post->foto->imagename;?>">
              <?php } ?>
            </div>
        </div>
   <?php }                    
}
?>