Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    retrieve all images from db

    hi,

    i want to retrieve all images which are present in mysql table.i want to display 5 images per row.but when i fetch image it shows one image only.here is my code.how to solve this problem.any of your help will be appreciated
    <?php

    $conn4=mysql_connect("localhost","","");
    mysql_select_db("jo",$conn4);


    $sql = "SELECT name, type, size, content FROM image_upload";
    $result = mysql_query($sql,$conn4) or die(mysql_error());



    list($name, $type, $size, $content) = mysql_fetch_array($result);

    header("Content-Disposition: attachment; filename=$name");
    header("Content-length: $size");
    header("Content-type: $type");
    echo $content;

    ?>

    thanks
    mrjameer

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    In a browser, to display an image, each image must be in the form -
    Code:
    <img src="a_url_that_results_in_an_image" alt="">
    You cannot directly output the contents of an image using inline code in the web page.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    so you will have to call your images like so..

    <img src="script.php?im=1" alt="" />
    <img src="script.php?im=2" alt="" />
    etc

    where script.php is similar to your above code,

    This is why storing images in a DB is a bad idea (IMO).
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •