0

I am trying to echo multiple images but i get the error:

"PHP Parse error: syntax error, unexpected '?>' in /public_html/View/Pages/Home.php on line 17".

Can you give me any guidance on how to fix it? code below

<?php
            for($i=0;$i<$length;$i++)  {
            echo ?><img class="meme-image" src="<?php $meme["$imd_id" == "$i"]->$path?>"><?php
            }
        ?>
Amit Gupta
  • 2,771
  • 2
  • 17
  • 31
sotos bic
  • 89
  • 7
  • 4
    `$meme["$imd_id" == "$i"]` doesn't look logical correct.. – Philipp Dec 21 '17 at 09:38
  • @Philipp with this line i try to get every meme image i have in my table. If it doesn't look logical what should i do instead? – sotos bic Dec 21 '17 at 09:43
  • what if images is 5 and loop runs only 3 times ? – TarangP Dec 21 '17 at 09:44
  • You do a compoarison, which equals to either `true` or `false`, then you try to get the element in the array which has this index, so you try `$meme[false]` and `$meme[true]`. I can guess this is not what you wanted. – Tobias F. Dec 21 '17 at 09:44
  • 1
    I suppose you wanna have `$meme["imd_id".$i]->$path` or `$meme[$imd_id.$i]->$path`. Depending on what `$img_id` is and/or what the keys in the array `$meme` really look like. – Jeff Dec 21 '17 at 09:46
  • @Jeff I see your point. The $meme is not array is an object – sotos bic Dec 21 '17 at 09:51
  • then it would be something like `$meme->{["imd_id".$i}->$path` or `$meme->{$imd_id.$i}->$path`. Still, the same issue. – Jeff Dec 21 '17 at 10:01
  • @sotosbic show us the output of `var_dump($meme);`. Put it before `for loop` . Also your code have syntax error, so change like this:-` ` – Alive to die - Anant Dec 21 '17 at 11:45
  • @AlivetoDie--Anantsingh the output is NULL – sotos bic Dec 21 '17 at 12:03
  • 1
    when your object us NULL then how's anything will work?Dam man, after so much comments and answers you are telling that input is null – Alive to die - Anant Dec 21 '17 at 12:03

1 Answers1

1

Try By this.

<?php
    for($i=0;$i<$length;$i++)  {
        echo '<img class="meme-image" src='.$meme[$imd_id == $i]->$path.' ">';
    }
?>

Note : You do not require to close php tag. instead of that insert this in php echo.and also you must read this For best practice.

TarangP
  • 2,711
  • 5
  • 20
  • 41
  • That might solve his syntax error, but not his problem showing images at all – Philipp Dec 21 '17 at 09:40
  • i tried your code but instead i got 40 more errors saying for undefined variables for img_id, meme and path and an error "Trying to get property of non-object" – sotos bic Dec 21 '17 at 09:45
  • please post your full code and change question title – TarangP Dec 21 '17 at 09:46
  • 1
    This still contains the expression `$meme["img_id" == "$i"]`, which will cause you trying to access `$meme[true]` or `$meme[false]`, which doesn't make sense. – Tobias F. Dec 21 '17 at 09:49
  • @TarangP i can't do that cause the website is in mvc model and it has like 10-15 php files. – sotos bic Dec 21 '17 at 09:50
  • `undefined variables for img_id` this errore mean by that problem is in your query. img id and all other data isn't found. check your query. – TarangP Dec 21 '17 at 09:52