473,831 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to display image from database?

35 New Member
i am doing a site for appliance center..
i need to display all the products that the company offers, but my problem is that i cant display ALL the images in my database.. the first entry on the database is the only one that displays..
i am using mysql as database

here's the code.. tell me what's my error and pls. kindly edit it..

**imgdata = it is where i store the image.. longblob is the data type
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     $errmsg = "";
  3.     if (! @mysql_connect("localhost","root",""))
  4.         {
  5.                 $errmsg = "Cannot connect to database";
  6.                             }
  7.     @mysql_select_db("upload");
  8.  
  9.     $gotten = @mysql_query("select imgdata from pix");
  10.     header("Content-type: image/jpeg");
  11.     while ($row = mysql_fetch_array($gotten))
  12.     {
  13.         print $row['imgdata'];
  14.  
  15.     }
  16. mysql_free_result($gotten);
  17. ?>
Feb 6 '08
48 41438
mirianCalin
35 New Member
Hi again...

Something like this..... for the page which displays all the images

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13.  
  14. while($i < $numRows){
  15. ?>
  16. <h1><?php echo mysql_result($rsPix,$i,"pixTitle"); ?></h1>
  17. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  18. <?php
  19. $i++;
  20. }
  21. ?>
hello!! thanks for replying again..
you're great.. it worked!!
mmm.. can i ask you again?
how can i display all the images in a table of 3 columns while the rows will depend on how many images is in my database

ex:
total # of images: 25
so, there will be 3 columns and 9 rows (the last row has only 1 image)

thanks again for the reply!!
Feb 10 '08 #11
harshmaul
490 Recognized Expert Contributor
Hi,
I appreciate your gratitude.

I don't get that last question fully.
What is the table structure for this new table (you can give me the create query if you like). I can try work it out or give you a proper solution, but i need more info this time...

:)
Feb 10 '08 #12
mirianCalin
35 New Member
Hi,
I appreciate your gratitude.

I don't get that last question fully.
What is the table structure for this new table (you can give me the create query if you like). I can try work it out or give you a proper solution, but i need more info this time...

:)
ah ok, i'll explain it again..
previously, you've given me the code for displaying all the images in my database.. when i tried it, it looks like this ( # for example is the image)
# # # # # # # #

i tried putting the code inside a table.
here's the code:
Expand|Select|Wrap|Line Numbers
  1. <table>
  2. <tbody>
  3. <?
  4. if($colCtr % $cols == 0)
  5. {
  6. ?> 
  7. <tr>
  8.     <td><img src="pix.php?pid=<?php echo mysql_result($rsPix,$i,"pid"); ?>"/></td>
  9. </tr>
  10.     <? $colCtr++; 
  11. }
  12. ?>
  13. </tbody>
  14. </table>
  15.  
  16. but the output looks like this:
  17. #
  18. #
  19. #
  20. #
  21. #
  22. #
  23. #
  24. #
  25.  
what i want is to be displayed it in 3 columns while the rows will depend on the number of images in my database
ex: total number of images is 7
Expand|Select|Wrap|Line Numbers
  1. display: 
  2.           # # #
  3.           # # #
  4.           #
  5.  
ex: total number of images is 11
Expand|Select|Wrap|Line Numbers
  1. display:
  2.           # # #
  3.           # # #
  4.           # # #
  5.           # #
  6.  
ex: total number of images is 6
Expand|Select|Wrap|Line Numbers
  1. display:
  2.           # # #
  3.           # # #
  4.  
please help me again..
and thanks for the reply..
thank you very much..
Feb 11 '08 #13
harshmaul
490 Recognized Expert Contributor
Hi, again!

Try using the div solution...
(the output code will be alot cleaner).
If you definately need tables i have another solution. but i'm not proud of that code... (very messy)

Div solution....
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13. ?>
  14. <div>
  15. <?php
  16. while($i < $numRows){
  17. ?>
  18. <div style="width:33%: float:left">
  19. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  20. </div>
  21. <?php
  22. $i++;
  23. }
  24. ?>
  25. </div>

Table solution.....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4.     {
  5.         $errmsg = "Cannot connect to database";
  6.     }
  7.  
  8. @mysql_select_db("upload");
  9.  
  10. $strSQL = "select * from pix";
  11. $rsPix = mysql_query($strSQL);
  12. $numRows = mysql_numrows($rsPix);
  13. $i = 0;
  14. ?>
  15. <table>
  16.     <tr>
  17.         <?php
  18.         while($i < $numRows){
  19.         ?>
  20.             <td>
  21.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  22.             </td>
  23.         <?php
  24.             if ($i%3 == 0){
  25.         ?>
  26.     </tr><tr>
  27.             <?php
  28.             }
  29.         ?>
  30.         <?php
  31.         $i++;
  32.         }
  33.         ?>
  34.         <?php
  35.         if ($numRows%3 > 0){
  36.         ?>
  37.             <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
  38.         <?php
  39.         }
  40.         ?>
  41.     </tr>
  42. </table>
Again i must say the code may need a spot of debugging.
Feb 11 '08 #14
mirianCalin
35 New Member
Hi, again!

Try using the div solution...
(the output code will be alot cleaner).
If you definately need tables i have another solution. but i'm not proud of that code... (very messy)

Div solution....
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13. ?>
  14. <div>
  15. <?php
  16. while($i < $numRows){
  17. ?>
  18. <div style="width:33%: float:left">
  19. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  20. </div>
  21. <?php
  22. $i++;
  23. }
  24. ?>
  25. </div>

Table solution.....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4.     {
  5.         $errmsg = "Cannot connect to database";
  6.     }
  7.  
  8. @mysql_select_db("upload");
  9.  
  10. $strSQL = "select * from pix";
  11. $rsPix = mysql_query($strSQL);
  12. $numRows = mysql_numrows($rsPix);
  13. $i = 0;
  14. ?>
  15. <table>
  16.     <tr>
  17.         <?php
  18.         while($i < $numRows){
  19.         ?>
  20.             <td>
  21.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  22.             </td>
  23.         <?php
  24.             if ($i%3 == 0){
  25.         ?>
  26.     </tr><tr>
  27.             <?php
  28.             }
  29.         ?>
  30.         <?php
  31.         $i++;
  32.         }
  33.         ?>
  34.         <?php
  35.         if ($numRows%3 > 0){
  36.         ?>
  37.             <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
  38.         <?php
  39.         }
  40.         ?>
  41.     </tr>
  42. </table>
Again i must say the code may need a spot of debugging.
hi.. i've tried the codes you've given me.. the first one still displays the images like this:
Expand|Select|Wrap|Line Numbers
  1. #
  2. #
  3. #
  4. #
  5. #
the 2nd one is the one that i need but there's something wrong, the first row has only 1 image but the succeeding rows are fine.. it displays like this:
Expand|Select|Wrap|Line Numbers
  1. #
  2. # # #
  3. # # #
  4. # # #
where's the problem with the code?
and where can i put this code

<td><center><?p hp echo mysql_result($r sPix,$i,"title" ); ?></center></td>

so that the image has a title under it?
thanks again for the reply..
Feb 11 '08 #15
harshmaul
490 Recognized Expert Contributor
Hi again mate,

First we'll sort out the table then we'll stick in the title....

i think i spoted the error with my code....


try this...


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4.     {
  5.         $errmsg = "Cannot connect to database";
  6.     }
  7.  
  8. @mysql_select_db("upload");
  9.  
  10. $strSQL = "select * from pix";
  11. $rsPix = mysql_query($strSQL);
  12. $numRows = mysql_numrows($rsPix);
  13. $i = 0;
  14. ?>
  15. <table>
  16.     <tr>
  17.         <?php
  18.         while($i < $numRows){
  19.         ?>
  20.             <td>
  21.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  22.             </td>
  23.         <?php
  24.         $i++;
  25.             if ($i%3 == 0){
  26.         ?>
  27.     </tr><tr>
  28.             <?php
  29.             }
  30.         ?>
  31.         <?php
  32.  
  33.         }
  34.         ?>
  35.         <?php
  36.         if ($numRows%3 > 0){
  37.         ?>
  38.             <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
  39.         <?php
  40.         }
  41.         ?>
  42.     </tr>
  43. </table>
i've moved the increment before the if statement.
Feb 11 '08 #16
mirianCalin
35 New Member
Hi again mate,

First we'll sort out the table then we'll stick in the title....

i think i spoted the error with my code....


try this...


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4.     {
  5.         $errmsg = "Cannot connect to database";
  6.     }
  7.  
  8. @mysql_select_db("upload");
  9.  
  10. $strSQL = "select * from pix";
  11. $rsPix = mysql_query($strSQL);
  12. $numRows = mysql_numrows($rsPix);
  13. $i = 0;
  14. ?>
  15. <table>
  16.     <tr>
  17.         <?php
  18.         while($i < $numRows){
  19.         ?>
  20.             <td>
  21.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  22.             </td>
  23.         <?php
  24.         $i++;
  25.             if ($i%3 == 0){
  26.         ?>
  27.     </tr><tr>
  28.             <?php
  29.             }
  30.         ?>
  31.         <?php
  32.  
  33.         }
  34.         ?>
  35.         <?php
  36.         if ($numRows%3 > 0){
  37.         ?>
  38.             <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
  39.         <?php
  40.         }
  41.         ?>
  42.     </tr>
  43. </table>
i've moved the increment before the if statement.
hello again..
i've tried the code, and it works!!
yehey!!.. thanks again!!

so, where will i have to put the code for the title of the image?
i want it to be under the image

ex:

# # #
image1 image2 image3

thanks again for the reply!!
thanks..
Feb 12 '08 #17
harshmaul
490 Recognized Expert Contributor
Hi again,
I'm getting excited its almost done!!!

can you not line break and place it under the photo? like this...


Expand|Select|Wrap|Line Numbers
  1.             <td>
  2.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
  3. <?php echo mysql_result($rsPix,$i,"pixTitle"); ?>"/>
  4.             </td>
If this will do excellent, and if not i do have another solution but thats gonna take a while to code out.
Feb 12 '08 #18
mirianCalin
35 New Member
Hi again,
I'm getting excited its almost done!!!

can you not line break and place it under the photo? like this...


Expand|Select|Wrap|Line Numbers
  1.             <td>
  2.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
  3. <?php echo mysql_result($rsPix,$i,"pixTitle"); ?>"/>
  4.             </td>
If this will do excellent, and if not i do have another solution but thats gonna take a while to code out.
hello again, hey thanks for the help..
really, really thanks..
but im still far from being done.. hehe..
i still have to make the images serve as a link to their features..
thank you very BIG!!
Feb 13 '08 #19
harshmaul
490 Recognized Expert Contributor
No problems mate, i like helping! (keeps me sane)
Feb 13 '08 #20

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

Similar topics

1
5889
by: Tan | last post by:
Hi I am desperate for any help with display image in Gridview I have a gridview contain surname , forename ..... and image. I could not display image as my database store the column image as image not text. I have tried all sort of things like converting the columns image to tempate so on and still could display image
3
3341
by: harish | last post by:
Hi friends I am facing problem as follow I can't display image from SQL Database to Picture box Control. Here are the codes that I am writing Dim arrPicture() As Byte = _
2
5019
by: RedSouljaz | last post by:
Hi, How to display image that was saved in database ms sql server 2000 into picture box. The field type that I use in database is Images I can save to database but cannot show from database. Thanks
3
5251
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 image file, then retrieve this image from database and display it in a Image web control dynamically(at runtime). The process after being displayed in the web control, user click insert/add button, it converts the image(jpeg) file to bytes and store it the database with Image or VarBinary...
7
5414
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed to show the image, and an image.php page that accesses the database, retrives the image data, and then (theoretically) prints the decoded data to the page. below is the view.php page code: problem area the img tag src no
7
4224
by: alexseow | last post by:
Query.asp <%@ LANGUAGE="VBSCRIPT" %> <!-- #include file="../../includes/dbconn.asp"--> <% dim MyRs, sqlstr, MyConn Response.Expires = 0 Response.Buffer = TRUE Response.Clear
1
1334
by: shalini328 | last post by:
I am using ASP.net 1.1 C# and database is MS access.Can you tell me how can i display image from database
1
3287
by: saadkhan | last post by:
I want to display image in <img> tag using database. I just need to know that how could i be able to define path or whatever to <img> tag. I have no probem in making queries to database.....plz help
5
2546
by: SafaaDalloul | last post by:
Please I want know How I can Display Image from database randomly when the web page refresh in Asp.net by C# code
1
3231
by: Laxmikant | last post by:
I am using VB6 as front end, Access 2007 as backend, crystal report 8 for reporting. I want to display image on my crystal report output, based on path saved in a table in Access Database. Is it possible to do so? If yes, how? Help ASAP.. Thanks in advance.
0
9793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10494
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10534
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10207
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7748
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.