0

I need some help..

I have a line of PHP that is echoing a url for me -

<?php foreach($day as $item) : ?>
        <li style="background: url('<?php echo http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=$item['tvdbid']?>')"><?php echo $item['show_name'] ?> </br> <?php echo $item['ep_name'] ?></li>
<?php endforeach ?>

The problem I have is that the URL here -

<li style="background: url('<?php echo http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=$item['tvdbid']?>')">

Appears to kill the code, so I assume my syntax is wrong, if I remove the "background stuff" the code works and the other 2 variables are mapped ok, i'm now wanting to set the backgroud of each li as per the image being returned from the API call, but I can't get it working..i'm sure someone here will sort it really easily for me..

Thanks

1 Answer 1

2

Yes you have syntax error in your code:

Modified Example:

<li style='background: url(<?php echo 'http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid='.$item['tvdbid'];?>)'>

Alternate Solution:

<?php
$url = "http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=".$item['tvdbid'];
?>

<li style='background: url(<?php echo $url; ?>)'>
Sign up to request clarification or add additional context in comments.

4 Comments

Ok, Your first modified example works for my "item" but my other variables now don't work so the output is - <li style='background: url("http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=78419)'> Sesame Street </br> Say Thank You to Your Face Day</li>
And your alternate solution (I like more) works for the other variables, but doesn't seem to resolve the .item['tvdbid'] variable?
@user3768497: fix small typo. try now
@user3768497: glad to help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.