I'm trying to display images by taking their file path from an sql table, but i'm having a lot of troubles.
Here is whats going on:
$image
is a variable containing the text "itemimg/hyuna.png"
which is path to an image.
$image = 'itemimg/hyuna.png';
I assumed I would be able to display the image outside of the php block like so:
<img src= "<? $image ?>" alt="test"/>
This doesn't work though for some reason.
So I thought maybe it's not able to read the variable outside the php block(i'm a beginner), so for testing i did:
<h1> "<? $image ?>" </h1>
It displays itemimg/hyuna.png
as a h1 banner.
Meaning it's accessing the varible fine.
So I thought maybe the path is wrong. So I tried:
<img src= "itemimg/hyuna.png" alt="test"/>
This displays the image perfectly.
So now I'm stuck scratching my head why the first bit of code displays nothing but the text "test"
from "alt="
Extra question:
How do I go about assigning a value from an sql cell to a variable?
I attempted the following with no luck:
$q = "select * from item where id=$id";
$results = mysql_query($q);
$row = mysql_fetch_array($results, MYSQL_ASSOC);
$image = ".$row['image'].";
item
is a table with a collumn: image
which contains file paths to images
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…