Page 1 of 1

how to load images from database?

Posted: Mon Apr 24, 2006 12:51 am
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]

Posted: Mon Apr 24, 2006 12:55 am
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.

Posted: Mon Apr 24, 2006 1:06 am
by lanny
i dont really understand...can you please explain more? or do you have any references or link about this ?
thanks in advance!

This might help

Posted: Mon Apr 24, 2006 2:08 am
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

Posted: Mon Apr 24, 2006 2:35 am
by lanny
however the example is not using the 'listbox'....how?

Posted: Mon Apr 24, 2006 1:55 pm
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...