PDA

View Full Version : Calling Images with an Array


Jeff_Coder
Sun 12th Aug '01, 5:25pm
I have a problem getting images from a database to display on a webpage. I can call the image by its id # with no problem, but the image is shown as ascii if I call it via an array. How can I make it work with the array? I don't want to have to code in the id #s for each image.

Here is the code to show the images, you can see it in action on this page: http://thor.osd.wednet.edu/~conorjr/news/nnews/test.php

<HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>
<P><IMG SRC=news2.php?id=10>
<?
mysql_connect("localhost","************","*********");
mysql_select_db("**********");

$show = mysql_query("select * from news ORDER BY id desc");
WHILE($news = mysql_fetch_array($show)) {

echo "<P>Image: <IMG SRC='$news[image]'>";
echo "<P>Description: $news[description]";
}
?>
</BODY>
</HTML>


Here is news2.php:


<?
if ($id) {

mysql_connect("localhost","********","************");
mysql_select_db("***********");

$query = "select image,filetype from news where id=$id";
$result = @MYSQL_QUERY($query);

$data = @MYSQL_RESULT($result,0,"image");
$type = @MYSQL_RESULT($result,0,"filetype");

Header( "Content-type: $type");
echo "$data";
};
?>

Mark Hensler
Sun 12th Aug '01, 6:05pm
You should stay away from using @. By using @, you prevent usefull error from being printed. Try the script again after removing the @ signs, and let us know what errors you get.

Jeff_Coder
Sun 12th Aug '01, 7:23pm
Thanks for the tibit about the @ signs, I obviously didn't know that. It turns out that I needed to replace the line calling the image with this:
echo "<P>Image: <IMG SRC='news2.php?id=$news[id]'>";

I am so glad that it was this simple. I've been working on this script off and on for the past 2 months.