how to load images from database?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lanny
Forum Newbie
Posts: 24
Joined: Thu Apr 06, 2006 10:09 am

how to load images from database?

Post by lanny »

how to load images from the database when i click the selection on the list box and it will be displayed on a particular frame. im using xhtml page, php and mysql.
thanks in advance..[/quote]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you're storing the raw binary image data in the database you'll have to create a script that retrieves a single image at a time sending the proper headers and things so a browser can properly display the images. Each time you want to reference one of these images it'll have to point to this script. Storing images in a database requires twice (at minimum) the RAM needed to hold the binary and will slow page response speeds among other things.
lanny
Forum Newbie
Posts: 24
Joined: Thu Apr 06, 2006 10:09 am

Post by lanny »

i dont really understand...can you please explain more? or do you have any references or link about this ?
thanks in advance!
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

This might help

Post by dibyendrah »

Dear lanny,
This http://www.devarticles.com/c/a/MySQL/Bl ... and-MySQL/link might help you.
I have taken the reference from this url earlier.

Cheers,
Dibyendra
lanny
Forum Newbie
Posts: 24
Joined: Thu Apr 06, 2006 10:09 am

Post by lanny »

however the example is not using the 'listbox'....how?
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post by The-Master »

you can store the files' name like "smile.jpg"
in a DB named "image_db" for example...
that is built like this:
id, image_name, image_format
and when you pull data you can display it like this:

Code: Select all

<html>
<head>
<title>something</title>
</head>
<frameset rows="48,*" frameborder=0 border=1>
<frame src="the_frame_with_the_list_box.htm" scrolling=no name="topframe">
<frame src="the_frame_that_shows_the_images.htm" name="bottomframe">
</frameset>
<body>
<form name="framecombo">
<select name="framecombo2" size=1>
<?php
$query = "SELECT * FROM image_db";
$result = mysql_query($query);

while($r=mysql_fetch_array($result)) { // this will display all the images in the db in a list
$img=$r["image_name"];
$img_f=$r["image_format"];
echo "<option value='images/$img.$img_f'>$img</option>";
}
?>
</select>&nbsp;<input type="button" value="Go!" onClick="jumpbox()"></p>
</form>

// the JScript...
<script language="javascript">
<!--
var openmode=1
var targetframe="particular_frame" // change this to the name of the particular frame you want

function jumpbox(){
var destination=eval("window.parent."+targetframe)
var thebox=document.framecombo
if (openmode==2)
destination=window.parent
destination.location=
thebox.framecombo2.options[thebox.framecombo2.selectedIndex].value
}
//-->
</script>
// the JScript end...
</body>
</html>
test it and tell me if this what you wanted...
Post Reply