473,943 Members | 29,092 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 41475
mirianCalin
35 New Member
okies, i never read that.

can you post some mark up this time.

Also your table definition would help
hi!!
what mark up?
my table name is "product"
the fields inside are:

pid (int) > product's id
title (text) > name of the product
imgdata (longlob) > the image
feature (text) > the product's feature.. this is also my problem when displaying.. like what i've mention above..
Feb 23 '08 #31
harshmaul
490 Recognized Expert Contributor
Hi again mate,

I think i know the problem...

replace the line that you have printing out the string with a piece of code that swaps carriage returns with <br/>'s

something like this.....


Expand|Select|Wrap|Line Numbers
  1. <?php echo nl2br(mysql_result($rsPix,$i,"feature")); ?>
BTW, markup is what you get when you view source in the browser after the PHP is run
Feb 23 '08 #32
mirianCalin
35 New Member
Hi again mate,

I think i know the problem...

replace the line that you have printing out the string with a piece of code that swaps carriage returns with <br/>'s

something like this.....


Expand|Select|Wrap|Line Numbers
  1. <?php echo nl2br(mysql_result($rsPix,$i,"feature")); ?>
BTW, markup is what you get when you view source in the browser after the PHP is run
hello.. thanks again for the reply..

this is the code for displaying the image's title, image & feature..
the only problem now is that i dont have a code for displaying the image..
the code only displays the title and feature..
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root","")) {
  4.         $errmsg = "Cannot connect to database";
  5.         }
  6. @mysql_select_db("upload");
  7.  
  8. $pid = $_GET['pid'];
  9. $strSQL = "SELECT * FROM sharp where (pid = '$pid')";
  10.  
  11. $rsPIX = mysql_query($strSQL);
  12. $num=mysql_numrows($rsPIX);
  13. $i=0;
  14.  
  15. if ($num > 0){
  16. $title = mysql_result($rsPIX,$i,"title");
  17. $description = nl2br(mysql_result($rsPIX,$i,"feature"));
  18. }
  19. echo $title . "<br>";
  20.  
  21. echo $description . "<br>";
  22. ?>
Feb 24 '08 #33
harshmaul
490 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root","")) {
  4.         $errmsg = "Cannot connect to database";
  5.         }
  6. @mysql_select_db("upload");
  7.  
  8. $pid = $_GET['pid'];
  9. $strSQL = "SELECT * FROM sharp where (pid = '$pid')";
  10.  
  11. $rsPIX = mysql_query($strSQL);
  12. $num=mysql_numrows($rsPIX);
  13. $i=0;
  14.  
  15. if ($num > 0){
  16. $title = mysql_result($rsPIX,$i,"title");
  17. $description = nl2br(mysql_result($rsPIX,$i,"feature"));
  18. }
  19. echo $title . "<br>";
  20.  
  21. echo $description . "<br>";
  22. ?>

Hi.

You've forgotton to put the image in....

Remember the page we made that displayed the imaged using an image tag?... we need to use that again on this page. This time we have the ID though. So it will be something like this....

Expand|Select|Wrap|Line Numbers
  1. <img src="pix.php?pixID=<?php echo mysql_result($rsPIX,$i,"PixID"); ?>"/>
Put that in the if statement and it should work!
Feb 24 '08 #34
mirianCalin
35 New Member
Hi.

You've forgotton to put the image in....

Remember the page we made that displayed the imaged using an image tag?... we need to use that again on this page. This time we have the ID though. So it will be something like this....

Expand|Select|Wrap|Line Numbers
  1. <img src="pix.php?pixID=<?php echo mysql_result($rsPIX,$i,"PixID"); ?>"/>
Put that in the if statement and it should work!
i've seen my mistake..
yeah, i've tried putting that code..
but i forgot to put this <? ?>
hehe.. thanks again..

this question is out of topic..
are you working?
how old are you friend?
Feb 24 '08 #35
mirianCalin
35 New Member
hey, got a problem again..
a 4th yr.student told me that i should not use 'longblob' for saving images because it's 'heavy' for the database and i will have a problem if i export/import the database from one computer to another..

do you have other suggestions for me?
i have only one week to finish this site.. *sighs*
Feb 26 '08 #36
Markus
6,050 Recognized Expert Expert
hey, got a problem again..
a 4th yr.student told me that i should not use 'longblob' for saving images because it's 'heavy' for the database and i will have a problem if i export/import the database from one computer to another..

do you have other suggestions for me?
i have only one week to finish this site.. *sighs*
Are you not able to store images on the server?
Feb 26 '08 #37
harshmaul
490 Recognized Expert Contributor
I agree with markusn00bs and disagree to an extent....

Agree buecause it is heavy for the server, and you can use image file uploads.

And disagree as if you images are in a DB you can ensure security alot more, like put the image view page behid a log in page
Feb 26 '08 #38
mirianCalin
35 New Member
Are you not able to store images on the server?
the images are only stored in the DB..
Feb 27 '08 #39
mirianCalin
35 New Member
I agree with markusn00bs and disagree to an extent....

Agree buecause it is heavy for the server, and you can use image file uploads.

And disagree as if you images are in a DB you can ensure security alot more, like put the image view page behid a log in page
so, do you have any suggestions?
i am not doing the site now 'cause i might start all over again..
Feb 27 '08 #40

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

Similar topics

1
5895
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
3348
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
5026
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
5261
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
5417
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
4229
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
1337
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
3293
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
2551
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
3235
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
9970
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
11133
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
11302
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
10666
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...
0
9866
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7392
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();...
0
6090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4913
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
2
4515
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.