php array in javascript images array

  • Themenstarter Themenstarter starfoxfs
  • Beginndatum Beginndatum
S

starfoxfs

Hi zusammen,

Ich möchte ein php Array aus dieser While Schleife :

PHP:
$bilder = array();
$sql = "SELECT NPL, NPLBLK, HMODTYP FROM ".$sqltab2." WHERE HMODTYP = '$mdlidkey' AND NPL = '$bildcode' ORDER BY id";
$result = $db->query($sql)or die(mysql_error());
while ($modell = $db->fetcharray($result)) {

$bilder[] = "./picturesthumb/$modell[NPL]/IMGE/$modell[NPLBLK].jpg";

}

an ein Javascript Array übergeben. Wie mache ich das ?

Code:
<script type="text/javascript"> 
var myImageNames = new Array( "<? echo $bilder; ?>"); 
var myImagesLoaded = 0;
 
So gehts fast ;) Problem ist noch das er während des ladens irgendwann aufhört warum auch immer

HTML:
$bilder = array();
$sql = "SELECT NPL, NPLBLK, HMODTYP FROM ".$sqltab2." WHERE HMODTYP = '$mdlidkey' AND NPL = '$bildcode' ORDER BY id";
$result = $db->query($sql)or die(mysql_error());
while ($modell = $db->fetcharray($result)) {

$bilder[] = "./picturesthumb/$modell[NPL]/IMGE/$modell[NPLBLK].jpg";

}

?>
<script type="text/javascript"> 
var myImageNames = new Array('<? echo implode("','",$bilder); ?>'); 

var myImagesLoaded = 0; 

function preload() 
{ 
   var t = new Array(); 

   for( var i = 0; i < myImageNames.length; i++ ) { 
      t[i] = new Image(); 
      t[i].src = myImageNames[i]; 
      t[i].onload = progress; 
   } 
} 

function progress() 
{ 

   document.getElementById( "progressbar" ).style.width = 
      ( 100 * ++myImagesLoaded / myImageNames.length ) + "%"; 

   if ( myImagesLoaded == myImageNames.length ) 
      window.location.href = "indexepc.php"; 
} 

</script> 
<body onload="preload()"> 
<div id="progressbar" style="background: red; width: 0; heigth: 20px;" /> 
</body>
 
Überwache mal zusätzlich zum onload noch den onerror-Event und lasse dir bei Eintreten desselben z.B. einen alert() ausgeben.
Wenn das passiert, konnte ein Bild nicht geladen werden, und deine Bedingung
Code:
 if ( myImagesLoaded == myImageNames.length )
...trifft nicht zu.
 
So nun schauts so aus :

HTML:
<script type="text/javascript"> 

var myImageNames = new Array("<? echo implode('","',$bilder); ?>"); 

var myImagesLoaded = 0; 

function preload() 
{ 
   var t = new Array(); 

   for( var i = 0; i < myImageNames.length; i++ ) { 
      t[i] = new Image(); 
      t[i].src = myImageNames[i]; 
      t[i].onload = progress; 
   } 
} 

function progress() 
{ 

document.getElementById("Status").src = "./scripts/loader.gif"; 

document.getElementById( "progressbar" ).style.width = 
      ( 100 * ++myImagesLoaded / myImageNames.length ) + "%"; 
	  
if ( myImagesLoaded == myImageNames.length ) {
window.location = "?ctg=show&action=mdlarea&modell=<? echo $typ; ?>&npl=<? echo $bildcode; ?>&area=<? echo $areacode; ?> ";

}else{ alert("Error Bilde konnte nicht geladen werden"); }

} 
</script> 
<body onLoad="preload()" bgcolor="#BFBFBF"> 
<img id="Status" width="100" height="100" src=""><br />
Bilder werden geladen bitte warten.<br /><br />
<div id="progressbar" style="background: red; width: 0; heigth: 20px;" />
</body>

zurückgeliefer bekomm ich vom Error Handler Error sprich die Bilder konnten nicht geladen werden aber warum :confused:

Im Quelltext siehts so aus :

HTML:
var myImageNames = new Array("./picturesthumb/13KPH3E1/IMGE/E__0100.jpg","./picturesthumb/13KPH3E1/IMGE/E__0200.jpg","./picturesthumb/13KPH3E1/IMGE/E__0300.jpg","./picturesthumb/13KPH3E1/IMGE/E__0400.jpg","./picturesthumb/13KPH3E1/IMGE/E__0500.jpg","./picturesthumb/13KPH3E1/IMGE/E__0600.jpg","./picturesthumb/13KPH3E1/IMGE/E__0700.jpg","./picturesthumb/13KPH3E1/IMGE/E__0800.jpg","./picturesthumb/13KPH3E1/IMGE/E__0900.jpg","./picturesthumb/13KPH3E1/IMGE/E__1000.jpg","./picturesthumb/13KPH3E1/IMGE/E__1100.jpg","./picturesthumb/13KPH3E1/IMGE/E__1200.jpg","./picturesthumb/13KPH3E1/IMGE/E__1300.jpg","./picturesthumb/13KPH3E1/IMGE/E__1400.jpg","./picturesthumb/13KPH3E1/IMGE/E__1500.jpg","./picturesthumb/13KPH3E1/IMGE/E__1600.jpg","./picturesthumb/13KPH3E1/IMGE/E__1700.jpg","./picturesthumb/13KPH3E1/IMGE/E__1800.jpg","./picturesthumb/13KPH3E1/IMGE/EOP0100.jpg","./picturesthumb/13KPH3E1/IMGE/EOP0200.jpg","./picturesthumb/13KPH3E1/IMGE/F__0100.jpg","./picturesthumb/13KPH3E1/IMGE/F__0200.jpg","./picturesthumb/13KPH3E1/IMGE/F__0300.jpg","./picturesthumb/13KPH3E1/IMGE/F__0400.jpg","./picturesthumb/13KPH3E1/IMGE/F__0500.jpg","./picturesthumb/13KPH3E1/IMGE/F__0600.jpg","./picturesthumb/13KPH3E1/IMGE/F__0700.jpg","./picturesthumb/13KPH3E1/IMGE/F__0800.jpg","./picturesthumb/13KPH3E1/IMGE/F__0900.jpg","./picturesthumb/13KPH3E1/IMGE/F__1000.jpg","./picturesthumb/13KPH3E1/IMGE/F__1100.jpg","./picturesthumb/13KPH3E1/IMGE/F__1200.jpg","./picturesthumb/13KPH3E1/IMGE/F__1300.jpg","./picturesthumb/13KPH3E1/IMGE/F__1400.jpg","./picturesthumb/13KPH3E1/IMGE/F__1500.jpg","./picturesthumb/13KPH3E1/IMGE/F__1600.jpg","./picturesthumb/13KPH3E1/IMGE/F__1700.jpg","./picturesthumb/13KPH3E1/IMGE/F__1800.jpg","./picturesthumb/13KPH3E1/IMGE/F__1900.jpg","./picturesthumb/13KPH3E1/IMGE/F__2000.jpg","./picturesthumb/13KPH3E1/IMGE/F__2100.jpg","./picturesthumb/13KPH3E1/IMGE/F__2200.jpg","./picturesthumb/13KPH3E1/IMGE/F__2300.jpg","./picturesthumb/13KPH3E1/IMGE/F__2400.jpg","./picturesthumb/13KPH3E1/IMGE/F__2500.jpg","./picturesthumb/13KPH3E1/IMGE/F__2600.jpg","./picturesthumb/13KPH3E1/IMGE/F__2700.jpg","./picturesthumb/13KPH3E1/IMGE/F__2800.jpg","./picturesthumb/13KPH3E1/IMGE/F__2900.jpg","./picturesthumb/13KPH3E1/IMGE/F__3000.jpg","./picturesthumb/13KPH3E1/IMGE/F__3100.jpg","./picturesthumb/13KPH3E1/IMGE/F__3200.jpg","./picturesthumb/13KPH3E1/IMGE/F__3300.jpg","./picturesthumb/13KPH3E1/IMGE/08L4201.jpg","./picturesthumb/13KPH3E1/IMGE/08L4202.jpg","./picturesthumb/13KPH3E1/IMGE/08L5201.jpg","./picturesthumb/13KPH3E1/IMGE/08L5501.jpg","./picturesthumb/13KPH3E1/IMGE/08L5604.jpg","./picturesthumb/13KPH3E1/IMGE/08L6301.jpg","./picturesthumb/13KPH3E1/IMGE/08M5301.jpg","./picturesthumb/13KPH3E1/IMGE/08R8001.jpg");
 
Naja, du rufst die Funktion ja bei jedem Ladevorgang eines Bildes auf, und solange nicht alle Bilder geladen sind, sind halt nicht alle Bilder geladen.

Erst wenn das letzte Bild geladen ist, kommt keine Meldung mehr...und sollte 1 Bild nicht geladen werden können, verläuft sich die Sache im Nirvana.
 

Neue Beiträge

Zurück