Link to home
Start Free TrialLog in
Avatar of James Murrell
James MurrellFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP show image based on value in mysql Database and the image folder #raspberrypi

Hi hope you can help last year this worked this year it is not: upgrade php i think

my php code is

<img class=polaroid  height=70 src=../images/drivers/".SUBSTR($_SESSION['Driver1'],0,4).".jpg/>

Open in new window


the html view score is

 <img class=polaroid  height=70 src=../images/drivers/ 3  .jpg/>

Open in new window



what i need is

 <img class=polaroid  height=70 src=../images/drivers/3.jpg/>

Open in new window


no spaces in the end part hope you guys can help. this is for a free fantasy F1 league i do with friends


I forgot to mention the images ref is stored in database like "3   Nico ROSBERG"
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

You missed all "" around tag values. Use this:
echo "<img class='polaroid'  height='70' src='../images/drivers/".SUBSTR($_SESSION['Driver1'],0,4).".jpg' />";

Open in new window

Avatar of James Murrell

ASKER

apologies i pasted a bit of code:  

whole code does have "" around
here is full code


echo "<h3><span>Your Team Name is :<b> " . $_SESSION['TeamName']. "</span> </h3>    " . 	"</b> Your choice of drivers are <b> " . substr($_SESSION['Driver1'] ,4).  "  </b>and <b>" . SUBSTR($_SESSION['Driver2'],4) .  " ,</b><p>  <img class=polaroid  height=70 src=../images/drivers/".SUBSTR($_SESSION['Driver1'],0,4).".jpg/><img class=polaroid height=80 src=/images/drivers/".SUBSTR($_SESSION['Driver2'], 0,4).".jpg  caption ".$_SESSION['Driver2'] ." <br /> <p>".

Open in new window

echo "<h3><span>Your Team Name is :<b> " . $_SESSION['TeamName']. "</span> </h3>    " .       "</b> Your choice of drivers are <b> " . substr($_SESSION['Driver1'] ,4).  "  </b>and <b>" . SUBSTR($_SESSION['Driver2'],4) .  " ,</b><p>  <img class=polaroid  height=70 src=../images/drivers/".SUBSTR($_SESSION['Driver1'],0,4).".jpg/><img class=polaroid height=80 src=/images/drivers/".SUBSTR($_SESSION['Driver2'], 0,4).".jpg  caption ".$_SESSION['Driver2'] ." <br /> <p>".
If $_SESSION['Driver1'] is "3   Nico ROSBERG" you have to use
substr(trim($_SESSION['Driver1']), 0, 1)

Open in new window

This code snippet appears to have a PHP parse error in it.

Please do this for us: Print out the contents of $_SESSION.  Use var_dump() to print it.  Post that information here.  Once we see the data we can give you the exact code you need to create the HTML document.

If you're new to PHP and want to find some good learning resources, this article can help:
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
Thanks Ray:    ok my error again here is full code
echo "<h3><span>Your Team Name is :<b> " . $_SESSION['TeamName']. "</span> </h3>    " . 	"</b> Your choice of drivers are <b> " . substr($_SESSION['Driver1'] ,4).  "  </b>and <b>" . SUBSTR($_SESSION['Driver2'],4) .  " ,</b><p>  <img class=polaroid  height=70 src=../images/drivers/".SUBSTR($_SESSION['Driver1'],0,4).".jpg/><img class=polaroid height=80 src=/images/drivers/".SUBSTR($_SESSION['Driver2'], 0,4).".jpg  caption ".$_SESSION['Driver2'] ." <br /> <p>".
        "<p>".
         "Your choice of teams are <b>" . SUBSTR($_SESSION['Team1'],4) .  " </b>  and <b>" . SUBSTR($_SESSION['Team2'],4) . " </b><p> <img class=polaroid  height=80 src=/images/teams/".SUBSTR($_SESSION['Team1'], 0,4).".jpg /> <img class=polaroid  height=80 src=../images/teams/".SUBSTR($_SESSION['Team2'], 0,4).
         ".jpg /><br /><p>Team win most Poles is:<b> " . SUBSTR($_SESSION['Total'],4)."</b> and your double point race is: <b> Race " . $_SESSION['MyProducts']." </b><p> <img class=polaroid height=80 src=../images/teams/".SUBSTR($_SESSION['Total'], 0,4).".jpg />  <img class=polaroid height=80 src=../images/circuits/".$_SESSION['MyProducts'].".jpg /><br/><p>" .
            "<P>Your choice of Postion for Lewis is : <b> " . $_SESSION['LewisEndofyearPosition'] .  "</b><br /><p>";

Open in new window




plus here is var_dump()
array(12) { ["TeamName"]=> string(8) "cs97jjm3" ["Email"]=> string(12) "ja@shdjs.com" ["FullName"]=> string(9) "jkasjkdjk" ["Driver1"]=> string(21) " 1 Lewis HAMILTON " ["Driver2"]=> string(18) " 3 Nico ROSBERG " ["Team1"]=> string(14) " 131 Mercedes " ["LewisEndofyearPosition"]=> string(1) "1" ["Team2"]=> string(15) " 9 Red Bull " ["Total"]=> string(12) "131 Mercedes" ["Password"]=> string(32) "b1a273f615207e00970cfb5d1e9a800d" ["MyProducts"]=> string(2) "14" ["submissionID"]=> string(1) "7" }

Open in new window


Thanks and apologies for not post full code originally
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks with explanation i understood problem:
You're welcome!
PHP functions are not case sensitive.  PHP variables, object property names, and array indexes are case-sensitive.
@Ray: thank you. I was sure everything was case-sensitive! Or better, I never dedicated a thought to that: I just always wrote in lowercase... And when I saw that SUBSTR and your comment about parse errors I thought you were talking about that, without noticing the missing param for 2 substr calls.
Well, another piece of knowledge in my pocket :-)
Cheers