472,334 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

display multiple image from database in php

i fetch single image . how i fetch multiple image. please send the code.
img1.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect('localhost','root','');
  3. $d=mysql_select_db("test");
  4. $q1="select * from cat ";
  5. $r1=mysql_query($q1);
  6. while($r=mysql_fetch_array($r1))
  7. {
  8. header("Content-type: image/jpeg");
  9. print $r['image'];
  10. }
  11. ?>
img2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con1=mysql_connect('localhost','root','');
  3. $d1=mysql_select_db("test");
  4. $q2="select * from cat";
  5. $r2=mysql_query($q2);
  6. //$r3=mysql_fetch_array($r2);
  7. ?>
  8. <table border="1">
  9. <tr>
  10.     <td>id</td>
  11.     <td>name</td>
  12.     <td>image</td>
  13.     </tr>
  14. <?php
  15. while($r3=mysql_fetch_array($r2))
  16. {
  17. ?>
  18. <tr>
  19. <td><?php echo $r3['id']; ?></td>
  20. <td><?php echo $r3['name']; ?></td>
  21. <td><img src="img4.php" height="100" width="100" /></td>
  22. </tr>
  23. <?php
  24. }
  25. ?>
  26. </table>
Mar 31 '10 #1

✓ answered by Atli

When you have PHP set the mime-type via the header function to that of an image, that requests becomes an image. Thus, you can not print more than a single image per request.

Which means that to print multiple images per page, you need to make multiple requests to the PHP script, each one representing a single image (just like you would with normal images). Usually you have two scripts, one that prints the HTML of the page, fetches the image meta-data and adds <img> tags, each one calling a second PHP script while passing it the ID of an image.

The second PHP script then just fetches and prints the data of that single image.

please send the code.
Not going to happen. We are happy to guide you through problems you may face while writing your own code, but we will not simply write it for you and hand it over.

15 9327
hello,
use mysql_fetch assoc();
and using "for" loop, or "if n while" u can retrieve all the images on single click
Mar 31 '10 #2
Atli
5,058 Expert 4TB
When you have PHP set the mime-type via the header function to that of an image, that requests becomes an image. Thus, you can not print more than a single image per request.

Which means that to print multiple images per page, you need to make multiple requests to the PHP script, each one representing a single image (just like you would with normal images). Usually you have two scripts, one that prints the HTML of the page, fetches the image meta-data and adds <img> tags, each one calling a second PHP script while passing it the ID of an image.

The second PHP script then just fetches and prints the data of that single image.

please send the code.
Not going to happen. We are happy to guide you through problems you may face while writing your own code, but we will not simply write it for you and hand it over.
Mar 31 '10 #3
In which program i use for loop and mysql_fetch_assoc .
Mar 31 '10 #4
PLEASE use my code then u send my answer .
Mar 31 '10 #5
Atli
5,058 Expert 4TB
@gaurav13477
We are not going to write this for you, mate. We are here to help you write the code, not to do it for you.

Try it yourself and let us know what exactly you are having problems with.
Remember to include the details we need to figure out what you are doing. Like: error messages, excepted output, actual output, code examples.
Mar 31 '10 #6
How i fetch multiple image from database here is my coding. i fetch single image.
where i get mistake. and which line.

img1.php
Expand|Select|Wrap|Line Numbers
  1.     <?php
  2.     $con=mysql_connect('localhost','root','');
  3.     $d=mysql_select_db("test");
  4.     $q1="select * from cat ";
  5.     $r1=mysql_query($q1);
  6.     while($r=mysql_fetch_array($r1))
  7.     {
  8.     header("Content-type: image/jpeg");
  9.     print $r['image'];
  10.    }
  11.    ?>

img2.php
Expand|Select|Wrap|Line Numbers
  1.   <?php
  2.     $con1=mysql_connect('localhost','root','');
  3.     $d1=mysql_select_db("test");
  4.     $q2="select * from cat";
  5.     $r2=mysql_query($q2);
  6.     //$r3=mysql_fetch_array($r2);
  7.     ?>
  8.     <table border="1">
  9.     <tr>
  10.        <td>id</td>
  11.        <td>name</td>
  12.        <td>image</td>
  13.       </tr>
  14.   <?php
  15.    while($r3=mysql_fetch_array($r2))
  16.    {
  17.    ?>
  18.    <tr>
  19.    <td><?php echo $r3['id']; ?></td>
  20.    <td><?php echo $r3['name']; ?></td>
  21.    <td><img src="img4.php" height="100" width="100" /></td>
  22.    </tr>
  23.    <?php
  24.    }
  25.    ?>
  26.    </table>
Apr 1 '10 #7
tell me exactly wt u need....y u used this header("Content-type: image/jpeg");
Apr 1 '10 #8
I get onle single image but in my database there are many other image.
I used for and mysql_fetch_assoc also but i can't get solve my problem
Apr 1 '10 #9
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect('localhost','root','');
  3. $d=mysql_select_db("test");
  4. $q1=mysql_query("select * from cat ");
  5. $r1 = mysql_num_rows($q1);
  6. if($r1>0)
  7. {
  8. while($r=mysql_fetch_assoc($q1))
  9. {
  10.  
  11. echo $r['image'];
  12. }
  13. }
  14. ?>
  15.  
use table td tr
Apr 1 '10 #10
I get output http://localhost/binary/pic3.php.
Instead of image
Apr 1 '10 #11
<img src="folder_image/<?php echo $r['image']; ?>" height="100" width="100" />
Apr 1 '10 #12
I think u can't get my question.
http://localhost/binary/pic3.php
Apr 1 '10 #13
ok what exactly u need...tell me clearly
Apr 1 '10 #14
Atli
5,058 Expert 4TB
The problem with the code above, the one you labeled "img1.php", is that you are printing all the images in the database, instead of just one.

When you set the content-type header to an image, the PHP code becomes an image and you need to print the data belonging to that image, and only that image.

Your code fetches all the images from the database and prints every one of them. The browser is only expecting data for one image, so when it gets all of your images, it can not render it correctly and just displays an error icon or the file name.

You should only be fetching and printing a single image, not all of them.
Apr 1 '10 #15
I used two file to display image.In second file to fetch image
<img src="img1.php" height="100" width="100"> In this i get single image.
And your answer is <img src="imq/. $row['img']" > where i write this code.
And where i make folder img.
i want to fetch mutiple image from database. but from my code get single
code . I send code also to u .
Apr 3 '10 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: RAllsopp | last post by:
I have a client who would like to have several pictures associated with one system. I have read about storing only the pathname to save OLE...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the...
1
by: Eric Keung | last post by:
Hi all, my case is I want to get an image from access database and I just know it's "OLE object" field type at access I also don't know how to...
2
by: Adam | last post by:
I have extensively searched for a solution. Below is my code that is contained in an aspx. When my browser hits this aspx, I just get the...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg...
6
by: yk | last post by:
Hi, Is it a technique available in html/javascript in order to display same image many many times on a same page? Because of a large page...
4
by: Milkstr | last post by:
I want to be able to display the same image a number of times, according to how is set by my database that drives the page. I have database of top...
1
by: rajbala.3399 | last post by:
Hai all, I need to get multiple image buttonsand wheni click on the image button it should display corresponding image on window and if i click...
3
by: Ian | last post by:
I have a form with a sub form, on the continues sub for I want to display some data along with a picture, on the On Current event I have the code:...
1
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage ...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.