Announcement

Collapse
No announcement yet.

Calling Images with an Array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling Images with an Array

    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
    PHP Code:
    <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:

    PHP Code:
    <?
    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";
    };
    ?>

  • #2
    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.

    Comment


    • #3
      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.

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...
      X