displaying multiple images

  • 14 years ago
    hi, after successfully storing the image, i have it displayed after..

    the problem is that, it prints the same picture that i've uploaded..

    the code is this:
    <?php
    require_once ("connect.php"); //connect to database
    $id = $_SESSION["id"];

    $result = mysql_query("select pic from pix where id ='$id'");

      while($row = @mysql_fetch_array ($result)){
      $imagetype = $row["filetype"];
      $image = $row["pic"];
      header ("Content-type: $imagetype");
      echo $image.'<br>';
       }
       
    ?>

    the (pic) filenames are different of course, but why does it displays the same picture?

    comments and suggestions pls....thanks!!!!

























  • 14 years ago
    Where does $id get set, and does it ever change during a session?

    Your query - is $id a unique value in the database or can you get multiple pictures back?

    If you can only get one picture back, you probably should replace your while() with an if().  If you can get multiple pictures back, then you probably need
      $result->MoveNext();
    as the last line of the while loop.  That will allow the loop to actually traverse the array.

    I hope that this helps!









  • 14 years ago
    Once you have output one header, and then sent the image you can't then send another header and another image. A good way to do this would be to have multiple image tags in your html or php document that calls this one.

  • 14 years ago
    Akicks,

    I am also having the same problem.
    U mentioned that if we use headers we will see one image only.
    So, how can i use image tag to display multiple image.
    Please help, its important to me.






  • 14 years ago

    Short Answer:

    Use multiple <img> tags in your html or php document that is getting the image.

    Long Answer:

    There are a couple of ways:

    The easiest way is to have multiple <img> tags. One for each picture you want to display.
    The other way is to make 1 image from multiple stored images. Have a look at this part of the manual for a lot of information on both how to do that.

    Using multiple <img> tags would be the better way to go, as most images on a web site are in different locations from each other (relatively). If you look at this forum you have the "Developer Fusion" logo on the top left and a "Hosted By" Image about half way down the left hand column. Can you imagine what it would be like if that was 1 image?

    Now have a look at "Discussion" and "Utilities" (the tabs at the top of the page). They would make a better candidate for the second method because the pictures are close to each other. But since they are links it only makes it hard to have them link to separate places (although still possible with image maps).









  • 14 years ago
    akicks,
    this is my code.
    here i am giving <img> tag.
    But i am not getting image, instead i am getting some coding(for that particular image)
    Please see the code and give the information.
    May be error in <img> tag.


    <?php
    $dbServer = "localhost";
    $dbDatabase = "mssi";
    $dbUser = "root";
    $dbPass = "";
    $sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server");
    $dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase");
    $dbQuery = "SELECT blobType, blobData FROM myBlobs";
    $i=0;
    $rows=mysql_num_rows($result);

    while($i < $rows) {
     $fileType = mysql_result($result, $i, "blobType");
     $fileContent=mysql_result($result, $i, "blobData");
    echo '<img src="'.$fileContent.'" width=32 height=32>';
    $i=$i+1;

    }
    ?>































  • 14 years ago
    You can't just dump binary image data into html.

    How do images normally work?

    <img src="fileName.type">

    The file name can be any type of image file that a browser will understand, or any program that can generate anytype of image file.

    so <img src="getPicture.php?id=1"> is valid. But it would be getPicture.php that returns an image, and not the program that wrote <img src="getPicture.php?id=1"> out to the browser.

    While your query is no doubt getting image data, you can not output image data when you are outputting html. Here is a brief example following what you have there.

    htmlPageWithImage.html
    <img src="getPicture.php?id=1"><!-- sends a request to get an image. -->

    getPicture.php
    <?php
    $id=$_GET['id'];//needs to be validated

    $dbServer = "localhost";
    $dbDatabase = "mssi";
    $dbUser = "root";
    $dbPass = "";
    $sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server");
    $dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase");
    $dbQuery = "SELECT blobType, blobData FROM myBlobs";

    $dbQuery.=" WHERE myBlobs.uniqueKey = '".$id."';";//

     $fileType = mysql_result($result, $i, "blobType");
     $fileContent=mysql_result($result, $i, "blobData");
     //output image file
     header("Content-type: $fileType");//tells the browser it is about to receive a picture
     echo $fileContent;//outputs picture
    //echo '<img src="'.$fileContent.'" width=32 height=32>';//nonsense removed
    ?>



































  • 14 years ago
    Hi akicks,
    Thanks for your immediate reply.
    I am writing the code like as u told but i didn' t get.

    mssi1.php
    <?php
    $dbServer = "localhost";
    $dbDatabase = "mssi";
    $dbUser = "root";
    $dbPass = "";
    $sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server");
    $dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase");
    $dbQuery = "SELECT blobType, blobData,blobId ";
    $dbQuery .= "FROM myBlobs";
    $result = mysql_query($dbQuery) or die("Couldn't get file list");
    $i=0;
    $rows=mysql_num_rows($result);

    while($i < $rows) {

    $blobId=mysql_result($result, $i,"blobId");
    $fileType = mysql_result($result, $i, "blobType");
     $fileContent=mysql_result($result, $i, "blobData");
    echo '<img src=getPicture.php?id="'.$blobId.'" width=32 height=32>';
    //include("getPicture.php")
    $i=$i+1;
    }
    ?>

    after clicking link goes to mssi1.php and display image symbols (not images). it does not goes to getpicture.php.
    If i put include("getPicture.php") in place of <img> it goes to getPicture and displays the first picture only


    getPicture.php
    <?php

    $_SESSION['blobId']=$blobId;
    $dbServer = "localhost";
    $dbDatabase = "mssi";
    $dbUser = "root";
    $dbPass = "";
    $sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server");
    $dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase");
     $dbQuery = "SELECT blobType, blobData FROM myBlobs where blobId=$blobId";
     $fileType = mysql_result($result, $i, "blobType");
     $fileContent=mysql_result($result, $i, "blobData");
     //output image file
     header("Content-type: $fileType");//tells the browser it is about to receive a picture
     echo $fileContent;//outputs picture
    //echo '<img src="'.$fileContent.'" width=32 height=32>';//nonsense removed

    ?>

    Please tell the reason. And give the appropriate solution for this.






























































  • 14 years ago
    Have a look at this example, paying attention to viewadd.php and getPicture.php.

    One thing I would like to mention.

    <img src="getPicture.php?id=$blobId">
                   ^                                        ^ quotes here.

    You should be able to copy the href or src from between the quotation marks and then paste it into your browsers address bar to see the image. if the url doesn't work in the browser, after exhausting all other options, perhaps there is something wrong with the url.

    From viewadd.php in the example: <img src="getpicture.php?id=<?php print $id; ?>" width="468" height="60">

    From your example code: echo '<img src=getPicture.php?id="'.$blobId.'" width=32 height=32>';














  • 14 years ago
    Akicks you are giving on example.
    but that is to display only one image dynamically from the database.
    But here is the case with displaying multiple images.

    Finally i tried in another way.
    I will upload the image path in to the database.
    For displaying the image i will retrieve the path from database and displays.

    Thank you Akicks for your response for my mails.











  • 14 years ago
    Hi Akicks,



    Sorry, I'm so new to this so please be easy.


    How do I build GD?
    I got this in the manual for gd-2.0.34:

    Win32 DLL users: if you are using MSVC,

    use the provided batch file makemsvcimport.bat to make a bgd.lib import library corresponding to the provided bgd.dll. Copy bgd.dll to your application directory, or to your Windows sytem directory. In the settings of your MSVC project, you MUST choose the "multithreaded DLL" library option under "code generation." mingw32 and cygwin users can simply link with the provided libbgd.a stub library in order to use the DLL.


    Where can I find this makemsvcimport.bat in my MSVC? Which settings should I use in creating a new Project in MSVC  (e.g. ATL COM AppWizard, Makefile, win32- DLL, etc.) ?

    P.S.
    I don't have C or C++ installed.

    Thank You in Advance and More Power!









  • 14 years ago
    as far as I know gd should already be installed on a windows version of php. If its not in your case then you can always redownload and re-install php.

    My windows php installation is from xampp. It installs Apache, mySQL, and php - and makes sure they all work.



  • 14 years ago

    Hi Andrew,

    Wow, thanks! I'll try that. Is it necessary to include the add-ons? ΓΌ






Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson