No announcement yet.

Load image from "image (database)" and display on screen?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Load image from "image (database)" and display on screen?


    Looking to retrieve an image that's stored in the database and display it on screen.

    The images are going to be product images that are retrieved based on what product is selected.

    How can I do this?

    Any help is appreciated.


  • #2
    Just by putting a field on your form with the correct file type (image/database)
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development /


    • #3
      Isn't that for uploading a image?

      I want to have a drop down with multiple products that when each product is selected it shows a larger product image off to the side ?

      How would I do that ?


      • #4
        Any other comments on this?


        • #5
          I would like to mention that storing images in a database is usually a bad idea for two reasons.

          a) It has a significant impact on performance and rendering.
          b) You can't just display the image, you always have to write code to render the blob data.

          The preferred method for database driven image presentation would be that you have the images
          stored in a directory and their filenames stored in the database.
          Now, all you need to do is to poll the DB for what filenames you want to display
          and then simply include the filename into an HTML attribute.

          But that's just me. :-)

          However, there is a solution for your problem.
          Create a blank application (blank_image.php) and use the following code (adjust it to your needs).

          sc_lookup(rs,"SELECT img_field FROM products WHERE prod_id = [v_sel]");
          //put your error validation here
          $pic = {rs[0][0]};
          header('Content-Type: image/jpeg');
          echo $pic;
          Place a label field ({picture}) and a select field ({sel1}) on the form/control.
          Fill {sel1} with the data (id, description) from your products table.
          Create an onChange ajax event for {sel1}.

          {picture} = "<img src='../blank_image/blank_image.php?v_sel=".{sel1}."' />";


          • #6
            Why so difficult? If the field is in the database, it can be displayed by creating a field of type image/database. That's it. I agree that it's in general not a good idea to store images in the database because of the size and problems if you need to migrate.
            Albert Drent
            aducom software netherlands
            scriptcase partner, reseller, support and (turn-key) development


            • #7
              Yeah, if the field is related to the table field. But try it on a control application or an unrelated field.
              As far as I understood the question, he wanted a select field of products and based on the selection
              a correspondend image should be retrieved and presented.
              I might be wrong, but I don't think you can do it with an image[database] field (didn't test it though).