•
•
•
•
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
![]() |
•
•
Join Date: Aug 2007
Posts: 21
Reputation:
Rep Power: 2
Solved Threads: 0
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
<?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
•
•
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,013
Reputation:
Rep Power: 6
Solved Threads: 68
You can retrieve only one image at a time.
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
Try to make this code as a function.
I'll give you an example:
I think that's it.
3,2,1...ZERO.
I'll give you an example:
php Syntax (Toggle Plain Text)
<?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"); function displayimage($id) { $query = "SELECT content,size,type FROM upload WHERE id='$id';";//$id is the id of your pic or whatever... $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); imagejpeg($content); //I have changed "print $content;" to this one... } $one=1; $two=2; $three=3; //just enter in the parameter of your function whatever id you want.. $one1=displayimage($one); $two2=displayimage($two); $three3=displayimage($three); echo '<img src="'.$one1.'">'; echo '<img src="'.$two2.'">'; echo '<img src="'.$three3.'">'; ?>
I think that's it.
3,2,1...ZERO.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
<?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.
$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.
•
•
Join Date: Aug 2007
Posts: 21
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
Try to make this code as a function.
I'll give you an example:
php Syntax (Toggle Plain Text)
<?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"); function displayimage($id) { $query = "SELECT content,size,type FROM upload WHERE id='$id';";//$id is the id of your pic or whatever... $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); imagejpeg($content); //I have changed "print $content;" to this one... } $one=1; $two=2; $three=3; //just enter in the parameter of your function whatever id you want.. $one1=displayimage($one); $two2=displayimage($two); $three3=displayimage($three); echo '<img src="'.$one1.'">'; echo '<img src="'.$two2.'">'; echo '<img src="'.$three3.'">'; ?>
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?
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- displaying image from database (PHP)
- How insert image into mysql database and retrieve (PHP)
- how to save image into database (VB.NET)
- how to convert images to binary to store in database (Java)
- retieve image from database (ASP.NET)
- please help! this is urgent> how to retrieve data to my tabpage without using data fo (C#)
- Download image from DB and view it... (C#)
- uploading image in database (PHP)
Other Threads in the PHP Forum
- Previous Thread: Sending html emails
- Next Thread: Mysql to Excel worksheet, need code



i forgot to change. it is belong to mine
Linear Mode