Avatar of James Murrell
James Murrell
Flag 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"
PHPHTML

Avatar of undefined
Last Comment
Marco Gasi

8/22/2022 - Mon
Marco Gasi

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

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>".
Marco Gasi

If $_SESSION['Driver1'] is "3   Nico ROSBERG" you have to use
substr(trim($_SESSION['Driver1']), 0, 1)

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Ray Paseur

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
James Murrell

ASKER
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
Marco Gasi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
James Murrell

ASKER
Thanks with explanation i understood problem:
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Marco Gasi

You're welcome!
Ray Paseur

PHP functions are not case sensitive.  PHP variables, object property names, and array indexes are case-sensitive.
Marco Gasi

@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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes