how to call an image from database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
hereznay
Forum Newbie
Posts: 2
Joined: Tue Oct 07, 2003 1:48 pm

how to call an image from database

Post 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
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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.
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post 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
hereznay
Forum Newbie
Posts: 2
Joined: Tue Oct 07, 2003 1:48 pm

Post 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
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post 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;
?>
Post Reply