User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,540 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 3,275 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 PHP advertiser: Lunarpages PHP Web Hosting
Views: 1636 | Replies: 11
Reply
Join Date: Aug 2007
Posts: 21
Reputation: rime is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rime rime is offline Offline
Newbie Poster

require urgent help to retrieve image from database

  #1  
Oct 11th, 2007
I have written the following code to retrieve image from mysql database:

<?php
include('dbinfo.inc.php');
include('../functions.php');
mysql_connect("localhost","username","password")
or die("Failure to communicate");
mysql_select_db("db")
or die("Could not connect to Database");

$query = "SELECT content,size,type FROM upload WHERE id=1;";
$result=mysql_query($query);
mysql_close();

$content=mysql_result($result,0,"content");
$size=mysql_result($result,0,"size");
$type=mysql_result($result,0,"type");

header('Content-Type: '.$type);
print $content;
?>

It is working.. Now I would like to retrieve multiple images at a time..
what shall I do?
please help.. its urgent
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,013
Reputation: ithelp will become famous soon enough ithelp will become famous soon enough 
Rep Power: 6
Solved Threads: 68
ithelp ithelp is online now Online
Veteran Poster

Re: require urgent help to retrieve image from database

  #2  
Oct 11th, 2007
You can retrieve only one image at a time.
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: require urgent help to retrieve image from database

  #3  
Oct 11th, 2007
Try to make this code as a function.
I'll give you an example:

  1. <?php
  2. include('dbinfo.inc.php');
  3. include('../functions.php');
  4. mysql_connect("localhost","username","password")
  5. or die("Failure to communicate");
  6.  
  7. mysql_select_db("db")
  8. or die("Could not connect to Database");
  9.  
  10. function displayimage($id)
  11. {
  12. $query = "SELECT content,size,type FROM upload WHERE id='$id';";//$id is the id of your pic or whatever...
  13. $result=mysql_query($query);
  14. mysql_close();
  15.  
  16. $content=mysql_result($result,0,"content");
  17. $size=mysql_result($result,0,"size");
  18. $type=mysql_result($result,0,"type");
  19.  
  20. header('Content-Type: '.$type);
  21. imagejpeg($content); //I have changed "print $content;" to this one...
  22. }
  23. $one=1;
  24. $two=2;
  25. $three=3;
  26.  
  27. //just enter in the parameter of your function whatever id you want..
  28. $one1=displayimage($one);
  29. $two2=displayimage($two);
  30. $three3=displayimage($three);
  31.  
  32. echo '<img src="'.$one1.'">';
  33. echo '<img src="'.$two2.'">';
  34. echo '<img src="'.$three3.'">';
  35.  
  36. ?>

I think that's it.
3,2,1...ZERO.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: require urgent help to retrieve image from database

  #4  
Oct 12th, 2007
use fetch_array command with while circle.
Reply With Quote  
Join Date: Aug 2007
Posts: 21
Reputation: rime is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rime rime is offline Offline
Newbie Poster

Re: require urgent help to retrieve image from database

  #5  
Oct 12th, 2007
Thanks ryan_vietnow for replying..

Basically I have a database where each row has three images..

And each row has an id, i.e. all three images have only one id..

so I am confused about the part in your code

$one=1;$two=2;$three=3;

what shall I do to make the code run for me.

Please Help
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: require urgent help to retrieve image from database

  #6  
Oct 12th, 2007
i will send you the code that i write soon. it support up to hundreds of images on one row...
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: require urgent help to retrieve image from database

  #7  
Oct 12th, 2007
<?php
$Get = $_GET['NewsID'];
$GetID = "select * from dbtable where ID='" . $Get . "'";
$Result = mysql_query($GetID);
$NumberofPicture = 3 // Define here have many columns stores your pictures data.

while($Write = mysql_fetch_array($Result))
{
$ID = $Write['ID'];

for($i = 1; $i < $NumberofPictures; $i++)
{
$Picture[] = $Write['Picture' . $i ]; // Name of column will appear like Picture1, Picture2
}
}
?>


<?php
// to print the data out from array
echo $Picture[1];
?>

i could not find the exact code i wanted to give you but i hope this would help you.
Reply With Quote  
Join Date: Aug 2007
Posts: 21
Reputation: rime is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rime rime is offline Offline
Newbie Poster

Re: require urgent help to retrieve image from database

  #8  
Oct 12th, 2007
Thanks fatihpiristine for replying.

can you please explain me the line

$Get = $_GET['NewsID'];

what is NewsID meant for?
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: require urgent help to retrieve image from database

  #9  
Oct 12th, 2007
ahaa i forgot to change. it is belong to mine

NewsID stands for the row id, requests and assing the data to $Get which is posted
Reply With Quote  
Join Date: Aug 2007
Posts: 21
Reputation: rime is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rime rime is offline Offline
Newbie Poster

Re: require urgent help to retrieve image from database

  #10  
Oct 12th, 2007
Originally Posted by ryan_vietnow View Post
Try to make this code as a function.
I'll give you an example:

  1. <?php
  2. include('dbinfo.inc.php');
  3. include('../functions.php');
  4. mysql_connect("localhost","username","password")
  5. or die("Failure to communicate");
  6.  
  7. mysql_select_db("db")
  8. or die("Could not connect to Database");
  9.  
  10. function displayimage($id)
  11. {
  12. $query = "SELECT content,size,type FROM upload WHERE id='$id';";//$id is the id of your pic or whatever...
  13. $result=mysql_query($query);
  14. mysql_close();
  15.  
  16. $content=mysql_result($result,0,"content");
  17. $size=mysql_result($result,0,"size");
  18. $type=mysql_result($result,0,"type");
  19.  
  20. header('Content-Type: '.$type);
  21. imagejpeg($content); //I have changed "print $content;" to this one...
  22. }
  23. $one=1;
  24. $two=2;
  25. $three=3;
  26.  
  27. //just enter in the parameter of your function whatever id you want..
  28. $one1=displayimage($one);
  29. $two2=displayimage($two);
  30. $three3=displayimage($three);
  31.  
  32. echo '<img src="'.$one1.'">';
  33. echo '<img src="'.$two2.'">';
  34. echo '<img src="'.$three3.'">';
  35.  
  36. ?>

I think that's it.
3,2,1...ZERO.




thanks ryan_vietnow.
I have tried your code but it is not working.
Is there any other way to solve the problem?
Reply With Quote  
Reply

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

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

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

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