mySQL +images help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Klavier
Forum Newbie
Posts: 7
Joined: Fri Jun 27, 2003 5:47 pm
Location: NJ

mySQL +images help!

Post by Klavier »

hi ok i am working with mySQL; pulling images into a table, i have the files showing correctly on one page, but not on this page.. i don't know why. all i get are broken images. heres what i am using

Code: Select all

<img src="/image/<?php echo$row["itemImage"]; ?>" >
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Can you post what outputs you are getting - what are the locations of the broken images? There are hundreds of reasons that this could not be working for u.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: mySQL +images help!

Post by Chris Corbyn »

Klavier wrote:hi ok i am working with mySQL; pulling images into a table, i have the files showing correctly on one page, but not on this page.. i don't know why. all i get are broken images. heres what i am using

Code: Select all

<img src="/image/<?php echo$row["itemImage"]; ?>" >
Hmmm... how are you actually retreiving the data from the database?

Do you do it the exact same way on your working page?

I would have throught you'd have to have a PHP script dedicated to serving the images, which specifies the correct content-type in the headers.

Code: Select all

&lt;img src=&quote;getImage.php?img=23&quote;&gt;
EDIT | Unless you're just getting the image names from the DB.... not the image file itself?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

eg

Code: Select all

$query = "SELECT image_url FROM table WHERE id = '{$id}'";
$result = mysql_query($result) or die (mysql_error());
while ($array = mysql_fetch_array($result))
{
  print "<img src=\"images/{$array['image_url']}\">";
}
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

like ~d11wtq said, all you're doing is dumping binary data to the browser. Unless proper headers are sent, it's not going to know what to do. Your best bet is to have a special image outputing page that attaches the appropriate headers along with the binary data.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

There are too many scenarios - Klavier => Post the script so that we can see whats going on
Post Reply