-2

i have the following code:

<?php

$events = Event::with('skoler')->get();
$skoleIsSet = $_GET['skoleId'];
$eventIsSet = $_GET['event'];


if($skoleIsSet && !$eventIsSet) {
    foreach($events as $event) {
        if($event['skole_id'] == $skoleIsSet) {
            ***$img = $event['img_url'];***
            echo '<div id="events">';
            ***echo '<img src="$img" height="100" width="100"/>';***
            echo '<h1>' . $event['title'] . '</h1>';
            echo '<p>Beskrivelse: ' . $event['description'] . '</p>';
            echo '<p>Pris: ' . $event['pris'] . '</p>';
            echo '<p>Dato: ' . $event['date'] . '</p></div>';

    }
   }
  } 

else {

foreach ($events as $event) {
    if ($event['skole_id'] == $skoleIsSet) {
    $bg = $event['img_url'];
        '<div id="events">';
        echo '<h1>' . $event['title'] . '</h1>';
        echo '<p>Beskrivelse: ' . $event['description'] . '</p>';
        echo '<p>Pris: ' . $event['pris'] . '</p>';
        echo '<p>Dato: ' . $event['date'] . '</p></div>';
    }
}
?>

I am supposed to show all events, with a picture. The url for the pictures is in the img_url column in my db. What is wrong with line number 8 and 10? The strong font option is not working, but the lines im referring to is marked with 6x *'s.

Thanks!

CHBR
  • 41
  • 7
  • 1
    We don't know because we don't know what your data looks like – John Conde May 09 '17 at 19:28
  • 1
    @JohnConde we know, because data in single quotes not interpolated. – u_mulder May 09 '17 at 19:28
  • This would have been solved easily @CHBR if you had inspected the element in your browser and would have seen `` instead of an actual URL. Next time, take a peek at your developer console -- that is what it is there for. – Jeremy Harris May 09 '17 at 19:30
  • @JeremyHarris Ermm, you're right. Note taken for future reference. Some times i am too quick to go to Stack Overflow! – CHBR May 09 '17 at 19:32

1 Answers1

1
echo '<img src="$img" height="100" width="100"/>';

You cannot include a variable directly into a string, if you're using single quotes. Either use double quotes (and escape the double quotes inside the string), or interrupt your string:

echo '<img src="' . $img . '" height="100" width="100"/>';
echo "<img src=\"$img\" height=\"100\" width=\"100\"/>";
rickdenhaan
  • 10,857
  • 28
  • 37