User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 374,004 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,741 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1482 | Replies: 38 | Solved
Reply
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

display image from databse

  #1  
Apr 1st, 2008
hello i am trying to display an image from a database which has just been uploaded by the user. when they go onto the next page the image should be displayed here.

I have been able to get it to display the path for the image that haas been stored using this code

 $sql= "SELECT * FROM images_broad";
	    $query = mysql_query($sql);
	    $result = mysql_fetch_array($query) or die (mysql_error());
             echo $result ['broad1'];

but when i try to use the img tag it displays nothing.

the path has been stored in the mysql table images_broad in broad1 and the path is stored in a variable called $newname2.

when the image is meant to be displayed the source code has then img tag as empty. I no it is going to be something silly stopping it from working but it would be nice if someone could show me why this is not working.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #2  
Apr 1st, 2008
the path of the file is store into a variable $newname2 and then broad1 in the mysql table is set to the value of the variable.

hope this helps people understand the problem a little bit more.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,041
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #3  
Apr 1st, 2008
I don't see variable $newname2 getting a value.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation: phper is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
phper's Avatar
phper phper is offline Offline
Junior Poster

Re: display image from databse

  #4  
Apr 1st, 2008
You have stored something like:

http://www.server.com/filelocation.png

in the database?

If so when fetching the values back from the db have you tried doing something like:

  1. $query = "SELECT * FROM images_broad";
  2. $result=mysql_query($query);
  3.  
  4. while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
  5. echo '<img src="'.$row['broad1'].'"/>';
  6. }

This should do the job! Any other problems let me know.

Regards,
Alex.
Last edited by peter_budo : Apr 3rd, 2008 at 10:52 am. Reason: Keep It Organized - please use [code] tags
If you find my post useful please add to my reputation!! Thanks!

ajtrichards web solutions
http://www.ajtrichards.co.uk
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #5  
Apr 2nd, 2008
that code definitely works. but it is printing the image out 6 times going down the page.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,041
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #6  
Apr 2nd, 2008
Do you have these files on a server so that we can check the output ? Because, I don't understand what exactly is the problem..
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #7  
Apr 2nd, 2008
if you go to www.acmert.co.uk/mercury this is what i have been working on. not all of it is set up yet but if you login (i will give you the password in a private message) and then click on the layout button then go to broadsheet upload some images and then go to the preview page you will see what i mean about the image being repeated.

also you will see the next problem i am having. instead of it placing the both images on the page it replaces the first one.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,041
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #8  
Apr 2nd, 2008
I checked it and this is what I find.
http://acmeart.co.uk/mercury/image/t...1207128520.jpg all the images have the same path. That is why the image is being repeated. While fetching the path from the table, check if it returns the right path. Then, there are only 2 input type='file'. So whenever you upload an image and then another (using the same upload file tag) it gets replaced.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #9  
Apr 2nd, 2008
each file upload has its own page so would this the name file matter or does this need to be different each time a new upload it completed.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,041
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #10  
Apr 2nd, 2008
Yep, I guess..
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 10:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC