How to retrieve image from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brijesh1234
    New Member
    • Sep 2008
    • 3

    #1

    How to retrieve image from database

    dear Sir/madam

    I am getting a problem while displaying a image from database

    Database : MSSQL2000

    I have a table named “Image” having following fields as

    Code:
    ImageId	int
    Image		Image
    FileType	image/jpeg
    I am using two PHP pages

    First PHP page (list.php) as

    [PHP]<?php
    $errmsg = "";
    if (! @mssql_connect( "10.147.16.167" ,"sa",""))
    {
    $errmsg = "Cannot connect to database";
    }
    @mssql_select_d b("epass");

    $strSQL = "select * from Image";
    $rsPix = mssql_query($st rSQL);
    $numRows = mssql_num_rows( $rsPix);

    $i = 0;

    while($i < $numRows){
    ?>

    <img src="pix.php?pi xID=<?php echo mssql_result($r sPix,$i,"pixID" ); ?>" width="100" height="100"/>
    <?php
    $i++;
    }
    ?>
    [/PHP]

    Second PHP page as (pix.php)

    [PHP]<?php
    $errmsg = "";
    if (! @mssql_connect( "10.147.16.167" ,"sa",""))
    {
    $errmsg = "Cannot connect to database";
    }
    @mssql_select_d b("epass");

    if (IsSet($_GET['pixID'])){
    //$gotten = @mssql_query("s elect Image from Image");
    $gotten = @mssql_query("s elect Image from Image where ImageId = ".$_GET['pixID']);

    header("Content-type: image/jpeg");
    while ($row = mssql_fetch_arr ay($gotten))
    {
    echo "************** ";
    print $row['Image'];

    }
    mssql_free_resu lt($gotten);
    }
    ?>[/PHP]

    Here I am running the list.php where an image box appears with cross button (no image is displaying in the image box)

    It is kindly requested to see the problem. I will be very grateful to you guys

    thanking you in anticipation
    Brijesh
    Last edited by Atli; Oct 16 '08, 08:16 AM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Brijesh.

    Please use &#91;code] tags when posting your code examples. (See How to ask a question)

    &#91;code=ph p] ...PHP code goes here... &#91;/code]

    Thank you.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      On line 16 in your second file, why do you echo a bunch of * chars before the contents of the image?
      That would surely corrupt the image.

      Comment

      • maheswaran
        New Member
        • Mar 2007
        • 190

        #4
        FYI

        While u want to display the image, do not ecoh any word in that area.

        Comment

        Working...