...

View Full Version : postloading with mysql images



soseki
08-01-2006, 01:27 PM
hello


I am trying to post load images stored in mysql db. I have tried this script:

<script type="text/javascript">
//<![CDATA[
function postLoad(){
if(!window.name.match(/preLoad.complete/gi)){
var images = new Array('img/EnglishOn.gif',
'img/EnterOn.gif',
'img/EntrerOn.gif',
'img/FrenchOn.gif');


var loader = new Array();
for(var i=0; i<images.length; i++){
loader[i] = new Image();
loader[i].src = images[i];
}
window.name = 'preLoad.complete';
}
}
//]]>
</script>



in my site it looks like this:

<script type="text/javascript">
//<![CDATA[
function postLoad()
{
var images = new Array('image.php?id_obrazu=8','image.php?id_obrazu=9','image.php?id_obrazu=10');
var loader = new Array();
for(var i=0; i<images.length; i++)
{
alert("loading image: "+i);
loader[i] = new Image();
loader[i].src = images[i];

}
}
//]]>
</script></head>
<body onload="postLoad()">


and image.php is:

<?
include("operacje_baza.php");
if(isset($id_obrazu))
{
mysqlconnect();//my function connecting to db
$zapytanie="SELECT OBRAZ FROM MZM_ZDJECIE WHERE MZM_ZDJECIE.ID=$id_obrazu";
$wynik=mysql_query($zapytanie);
$row=mysql_fetch_array($wynik);
header("Content-type: image/jpeg");
echo $row['OBRAZ'];

mysql_close();

}

?>

image.php works fine showing requested images but postLoading does not work. I get an alert from script with "loading image" and number but it does not postload.

If any one have idea how to solve my problem please write it:)
generally i need postloading images from mysql db:)

glenngv
08-02-2006, 04:23 AM
Try this and see what it says in the alert.


for(var i=0; i<images.length; i++)
{
loader[i] = new Image();
loader[i].onerror = function(){alert("Error loading "+this.src)};
loader[i].onload = function(){alert("OK loading "+this.src)};
loader[i].src = images[i];
}

soseki
08-02-2006, 10:49 AM
i did it and it shows one alert window: "ok loading: server/image.php?id_obrazu=8". no error or another ok loading alerts. But this image (id=8) is already loaded while loading page, so post load does not work. Sorry for my lame questions but i have just started with php and js. Only have experience with coding in c++ and java.

/edit
i checked in ie and its working ok but in firefox still does not. any ideas why?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum