Page 1 of 1

how to call an image from database

Posted: Tue Oct 07, 2003 1:48 pm
by hereznay
I am a php/mysql newbie and have searched high and low for this answer all morning with no luck.

On my site of movie reviews I want to set up my database to display:

moviename
ratings (graphic)
buy dvd (link)

2 Questions.

1. How do I set up the col/row to pull the appropiate star rating from the images directory?

2. How is it possible to have linked files dispaly from the database? When I put it in now, it comes up as text.

Thanks in advance!
Nay

Posted: Tue Oct 07, 2003 4:38 pm
by Paddy
Ok, I will answer question 1. Assume the table is named movies. Just put the image name of the rating in the ratings field and place the actual image in a folder named images. Then do code as follows. (I left out the connection functions.

Code: Select all

<?php
$result = mysql_query("select * from movies") or exit();
$row = mysql_fetch_row($result);
?>
<img src="images/<?php echo($row[1]); ?>">
Could you perhaps reword Q2? I am not sure what you are asking.

Posted: Tue Oct 07, 2003 5:15 pm
by mrvanjohnson
In Q2 are you referring to URl?

So you do a

Code: Select all

<?php
echo $row['url'] ;

?>
and you get

Code: Select all

www.sample.com
You need to do this

Code: Select all

<?php
echo "<a href="".$row['url']."">".$row['url']."</a>" ;

?>
to make the link "active" http://www.sample.com

Posted: Tue Oct 07, 2003 5:54 pm
by hereznay
Paddy,

I actually understand what you wrote and now I "get it".

mrvanjohnson,

You nailed exactly what I was asking about.


Thank you both so very much!
:D ,
nay

Posted: Tue Oct 07, 2003 8:23 pm
by Cruzado_Mainfrm
the best way is

Code: Select all

<?php
$i=0;
$result = @mysql_query("SELECT imagedata FROM images WHERE id = '$i'");
$img = mysql_result($result,0,'imagedata'); 
header('Content-type: image/jpeg');
echo $img;
?>