how do i display an image from the database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • howzy
    New Member
    • Feb 2008
    • 2

    how do i display an image from the database?

    Hello I am new to the database world and Ive learned how to do a few things storing text is easy. i found that out but trying to get an image to show up on a page is difficult and i cant seem to find the correct way to call it up in php so it will display..What i am trying to do is build a search engine for a furniture companys rug collection...so that the rug type style size and an image next to that will show up...

    this is my php code
    [php]<?php # rug search_results. php
    $connection = mysql_connect(' *', '*', '*') or die(mysql_error ());
    if (!$connection) {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db ("rugs", $connection);
    $rugtype_id = "";
    if (isset($_GET['rugtype_id'])) {
    $rugtype_id = $_GET['rugtype_id'];
    }
    if ($rugtype_id != NULL) {
    $query = "SELECT * FROM rugs WHERE rugtype_id=$rug type_id";
    $result = mysql_query($qu ery, $connection);
    if (mysql_num_rows ($result) > 0) {
    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
    echo "{$row['itemnumber']}";
    echo "<br />";
    echo "{$row['rugname']}";
    echo "<br />";
    echo "{$row['origin']}";
    echo "<br />";
    echo "{$row['fabric']}";
    echo "<br />";
    echo "{$row['image']}";

    } // End of WHILE loop.
    }
    else { // No
    echo '<p class="error">' ;
    echo "There are no rugs listed for the given request.";
    echo "</p>";
    }
    }
    else {
    echo '<p class="error">' ;
    echo "Please select a valid rug type from the drop-down menu in order to view the rugs.";
    echo "</p>";
    }
    ?>[/php]please tell me what im doing wrong any input would help thanks

    Dan
    Last edited by ronverdonk; Feb 27 '08, 06:12 PM. Reason: code within tags
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Have a look at this tutorial.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Welcome to TSDN!
      please tell me what im doing wrong any input would help thanks
      What you are doing wrong anyway is NOT enclosing your code within coding tags! You make it hard on our members to help ytou when you present them with messy formatted code.

      See the Posting Guidelines.

      moderator

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Your thread title is 'How to upload an image blob', but from your code the image is already in the database and your question is about displaying an image.

        If the latter is the case, you should have a look at thread Showing an image from the database because that handles this problem.

        Ronald

        Comment

        • howzy
          New Member
          • Feb 2008
          • 2

          #5
          thanks to all

          yes the image data is already in the blob. But all i seem to be getting back is what looks like binary data and not the actual image..i would love to know if there is a way in php to bring up the image. Most of the tutorials i found are how to browse and add an image to a database...i just want people to do a search and then have the image of the item and details about the item to come up. so far i can get the details to show up but im having zero luck on getting the actual image to show.

          thanks

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Look at the thread I showed you in my previous post. Exactly the same problem.

            Ronald

            Comment

            Working...