Forum Moderators: coopster

Message Too Old, No Replies

images from a database

         

jyogit

2:33 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



ok im really thick at this and need advice
i need to get a pile of images from my database and into my webpages.
i can connect and fetch the results fine.
i need to asign these results as my imagename and load them one under the other in my webpage.
all the images are the same size thats no problem.
i just cant fathom how to asign it to the image.
please help....
anyone?
by the way im running php on this page for my nav etc so php solution would be fine.

jatar_k

4:32 pm on Feb 13, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do you have any code at all yet?

do you need references for all the parts of the process?

just checking before I dig them all up ;)

jyogit

7:06 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



thanks jatar
i have the begining of what i need which is this...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #000000;
}
body,td,th {
color: #9900FF;

}
-->
</style>
<div align="center">
<?php
$con = mysql_connect("mysql#*$!#*$!#*$!#*$!#*$!", "#*$!#*$!#*$!#*$!", "#*$!#*$!#*$!x");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("#*$!#*$!#*$!", $con);

$result = mysql_query("SELECT * FROM geri ORDER BY cd");

while($row = mysql_fetch_array($result)){
echo $row['cd'];
echo "<br />";

}

mysql_close($con);
?></head>

<body>

<div align="center"><tr><td><img src="<?= $row[cd] ?>"></td></tr></div>
</body>
</html>

i left in the echo $row['cd']; line just to check that im getting the right information back from the database and thats fine.

it adds a blank image box though instead of an image.
and i want to see all images in a row underneath each other in the site.

cant seem to figure that bit out yet.

the image name in the database should be all i need to show the image surely?
ive submitted the full path and the local path but i still get a blank image placed on screen.

heres what im getting when i goto the page... <snip>

ive had a few suggestions from someone but i still cant get it to work.

the images are all the same size and will fit into a table down the middle of the site.

hope someone can help

jeff

[edited by: eelixduppy at 7:17 pm (utc) on Feb. 13, 2008]
[edit reason] no URLs, please [/edit]

Lived

9:35 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



<?
$result = @mysql_query("SELECT * FROM table WHERE imgid=" . $img . "", $dbcnx);

if (!$result)
{
echo("Error performing query: " . mysql_error() . "");
exit();
}

while ( $row = mysql_fetch_array($result) )
{
$encodeddata = $row["sixfourdata"];
}

header('Content-type: image/jpeg');

echo base64_decode($encodeddata);
?>

You need something like this to get it to work....

jyogit

10:00 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



thanks for that but as a complete novice thats confused me even more.

if anyone has the time to talk me through this id be grateful.

phranque

11:19 pm on Feb 13, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i need to get a pile of images from my database

- are your images in files or are they in a blob column in the db?

- if they are in files, the src parameter needs to be a http: protocol url, not a file path.

- have you tried accessing the file url directly?

jyogit

11:26 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



i thought i could do this by just adding the path to file into the database,retrieve the file paths and show then on a page in a table.so i have added some paths ie...images/redress.jpeg

i can do this succesfully and retrieve the results and echo them onto the page.
what i cant get them to do is show up as an image.

the information that is retrieved is the file path that i put into teh database.
i thought this would do want i want but all it shows is an empty image box on the webpage.
and it only shows 1 and not the full retrieved information.

im stuck now

?>
<div align="center"><tr><td><img src="<?= $pic[cd]; ?>" width="500" height="250" /><?php echo "<br />";?> </td></tr></div>

jatar_k

12:52 am on Feb 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



is the path correct? the blank box sounds like the path to the image is not correct

as phranque mentioned, can you access these images in your browser?

here's a wild guess

images/redress.jpeg

so I am guessing images is located at the root of the site and if your path is like the above it may not work, depending on where on the site you are, maybe try this

/images/redress.jpeg

which is an absolute path from root, the equivalent full url would be

http://www.example.com/images/redress.jpeg

jyogit

1:14 am on Feb 14, 2008 (gmt 0)

10+ Year Member



yes,ive tried both those routes with database entries in both formats but still get the blank image logo.

i can see the files in my browser and have used them before in the website so it shouldnt be a problem.

im lost again now...
tried everything you have all suggested but it still wont work.

if anyone can write me a full example of what i need i'd be grateful.

phranque

2:39 am on Feb 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you still haven't clearly answered whether you can access the image directly.

have you viewed the image file in your browser in html?
or have you viewed the image file by directly accessing the image as http://www.example.com/images/redress.jpeg?

(and is it really .jpeg or is it .jpg?)

is your script running in the server root directory?

jyogit

11:05 am on Feb 14, 2008 (gmt 0)

10+ Year Member



sorry but yes to all the above.
i had noticed that i had written jpeg by mistake....

i have tried it with different images also not just that one.
yes the script is running in the root as is the full pages that i need this bit of imagery for.

i must be missing something somewhere but i cant put my finger on it.

jatar_k

2:13 pm on Feb 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you can put this in your browser and see the image
http://www.example.com/images/redress.jpg

then you can put this
<div align="center"><tr><td><img src="<?= $pic['cd']; ?>" width="500" height="250" /><br /></td></tr></div>

if $pic['cd'] has a value of /images/redress.jpg

you should view source on these pages to see what html is actually getting output, this seems like a path problem, you need to be 100% sure that your path is getting output properly and then check the html to be sure it is correct, then you can scratch those off the list and look to something else

jyogit

9:24 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



tried that
tried emptying database and just adding a few entires.
i can echo and show whats been outputted from database query which is the correct path to the image file.
i still get the empty image box on screen though.
i have tried the database being set to text and to longblob and still no results.

i dont want to give up on this idea cos its still the easiest way to overcome what i need to do,im sure.

coopster

4:02 pm on Feb 16, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you certain it is not your image format?

If you have stored your JPG images in a CYMK format and view them in MSIE you will get an empty image container. If you use Firefox and attempt to view a CYMK-format JPG in the browser you will get an error message something like ...

The image “file:///C:/path/to/image/CMYK.jpg” cannot be displayed, because it contains errors.

jyogit

4:09 pm on Feb 16, 2008 (gmt 0)

10+ Year Member



thanks coopster but wheelie helped me out and it now works.
but thanks for the help.

really glad i found this site.
the help is invaluable