0

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>";
    }                    
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
K.Wayne
  • 87
  • 10

3 Answers3

3

Use this in echo statement:

<img class='myimage'src='userdata/'".$post->foto->imagename."'> 

Instead of:

<img class='myimage'src='"userdata/".$post->foto->imagename."'>
Jayesh Chitroda
  • 4,987
  • 13
  • 18
  • Already I have tried, its not helping. – K.Wayne Jun 25 '16 at 06:13
  • $user = new User(); $user->getInfo(); $img_prof = new ImageProfile(); $fotos = $img_prof->getProfile(); if(isset($user2)){ $postimet = $user->allMyPosts($_GET['id']); }else{ $postimet = $user->allMyPosts($_SESSION['id']); } foreach($postimet as $post){ $firstname = $user->getUserById($post->userid)['first']; $lastname = $user->getUserById($post->userid)['last']; foreach($fotos as $foto){ – K.Wayne Jun 25 '16 at 06:23
  • Exactly, now is working perfectly, Thanks man :) – K.Wayne Jun 25 '16 at 06:29
  • @K.Wayne please up-vote the answer too and remove your above code comment. it's looking ugly. thanks – Alive to die - Anant Jun 25 '16 at 06:37
0

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 }                    
}
?>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
0

You try to find something like this?

<?php

    $html->tag('doctype')->alone('html')->tag();
    $html->tag('html')->lang('en');

        $html->tag('head');
            $html->tag('meta')->charset('utf-8')->tag();
            $html->tag('meta')->httpequiv('X-UA-Compatible')->content('IE=edge')->tag();
            $html->tag('meta')->name('viewport')->content('width=device-width, initial-scale=1')->tag();
            $html->tag('meta')->name('description')->content('Brosta Tools')->tag();
            $html->tag('meta')->name('author')->content('Brosta')->tag();
            $html->tag('title')->text('Brosta Tools')->tag();
            $html->tag('link')->href('assets/plugins/bootstrap/css/bootstrap.min.css')->rel('stylesheet')->tag();
            $html->tag('link')->href('assets/plugins/bootstrap/css/simple-sidebar.css')->rel('stylesheet')->tag();
            $html->tag('link')->href('assets/plugins/prism/css/prism.css')->rel('stylesheet')->tag();
            $html->tag('link')->href('assets/plugins/normalize/css/normalize.css')->rel('stylesheet')->tag();
            $html->tag('link')->href('assets/plugins/brosta/css/brosta.css')->rel('stylesheet')->tag();

            $html->tag('script')->src('assets/plugins/bootstrap/js/jquery.js')->type('text/javascript')->tag();
            $html->tag('script')->src('assets/plugins/bootstrap/js/bootstrap.min.js')->type('text/javascript')->tag();
            $html->tag('script')->src('assets/plugins/prism/js/prism.js')->type('text/javascript')->tag();
            $html->tag('script')->type('text/javascript')->text('$("#menu-toggle").click(function(e) {e.preventDefault(); $("#wrapper").toggleClass("toggled"); });')->tag();
            $html->tag('script')->type('text/javascript')->text('
                window.onload = function () { 
                    var x = document.getElementsByClassName("token");
                    var i;
                    for (i = 0; i < x.length; i++) {
                        var variable = x[i].getAttribute("class").replace("token ", "");
                        var text = x[i].innerText.trim().replace("$", "");
                        if(!/[^a-zA-Z0-9]/.test(text) || text.indexOf("_") >= 0) {
                            x[i].className +=" " + variable + "-" + text;
                        }
                    }
                }
            ')->tag();
        $html->tag();

        $html->tag('body')->class('brosta');

            $html->include('snippets.brosta.navbar');

            $html->tag('div')->class('container-fluid brosta');
                $html->tag('div')->id('wrapper');
                    $html->tag('div')->id('sidebar-wrapper');
                        $html->tag('ul')->class('sidebar-nav');

                            $data = [
                                ['link' => '/Instalation', 'text' => 'Instalation'],
                                ['link' => '/Html', 'text' => 'Html']
                            ];

                            foreach($data as $link)
                            {
                                $html->tag('li');
                                    $html->tag('a')->href($link['link'])->text($link['text'])->tag();
                                $html->tag();
                            }

                        $html->tag();
                    $html->tag();
                    $html->tag('div')->id('page-content-wrapper');
                        $html->tag('div')->class('row');
                            $html->tag('div')->class('col-lg-12');
                                $html->tag('div')->class('panel panel-default');
                                    $html->tag('div')->class('panel-heading clearfix')->text('Without Time')->tag();
                                    $html->tag('div')->class('panel-body');
                                        $html->tag('p')->text('Make a file in your root public server. Ex: <code class="language-php">C:\xampp\htdocs\index.php</code>')->tag();
                                        $html->tag('pre')->class('language-php');
                                            $html->tag('code')->class('language-php')->text($html->specialChars('views/content.php'))->tag();
                                        $html->tag();
                                    $html->tag();
                                $html->tag();
                            $html->tag();
                        $html->tag();
                    $html->tag();
                $html->tag();
            $html->tag();
        $html->tag();
    $html->tag();

echo $html->get();
John Stamoutsos
  • 191
  • 3
  • 16