var mygallery=new fadeSlideShow({
wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [<?php $q2 = mysql_query("select * from home_flash");
$i = 0;
while($res = mysql_fetch_array($q2))
{
$image[$i] = $res[1];
$text[$i] = $res[2];
$str = "['images/fla/".$image[$i]."','','','".$text[$i]."'],";
echo $str;
$i++;
} ?>
//<--no trailing comma after very last image element!
],
displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 500, //transition duration (milliseconds)
descreveal: "always",
togglerid: ""
})
In IE I got an error
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2)
Timestamp: Sat, 20 Mar 2010 06:22:10 UTC
The error message is telling you that your imagearray[] has not been initialised and the reason for that is because you cannot have php code mixed in with javascript as in:
Code:
var mygallery=new fadeSlideShow({
wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [<?php $q2 = mysql_query("select * from home_flash");
$i = 0;
while($res = mysql_fetch_array($q2))
{
$image[$i] = $res[1];
$text[$i] = $res[2];
$str = "['images/fla/".$image[$i]."','','','".$text[$i]."'],";
echo $str;
$i++;
} ?>
//<--no trailing comma after very last image element!
],
You can have php embedded in html code though. PHP code is a server side scripting language and so is executed on the server before the ouput html is sent back to the browser. PHP does not go through javascript looking for php code to execute.
When the html is received by the browser, then the javascript is executed.
If you want to execute php code from javascript you have to use AJAX.
var mygallery=new fadeSlideShow({
wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [<?php $q2 = mysql_query("select * from home_flash");
$i = 0;
while($res = mysql_fetch_array($q2))
{
$image[$i] = $res[1];
$text[$i] = $res[2];
$str = "['images/fla/".$image[$i]."','','','".$text[$i]."'],";
echo $str;
$i++;
} ?>
//<--no trailing comma after very last image element!(Are you sure theres no trailing comma)
],
displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 500, //transition duration (milliseconds)
descreveal: "always",
togglerid: ""
})
commas in json objects can be a trick to javascript when we deal with the browser.
Watch for this kind of error many of js programmers suffer.
Let me give you an example:
Code:
//this will work on FF browser while not with IE
var obj= {
key: "Some Value", //notice the comma here
};
alert (obj. key);
var mygallery=new fadeSlideShow({
wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [<?php $q2 = mysql_query("select * from home_flash");
$i = 0;
while($res = mysql_fetch_array($q2))
{
$image[$i] = $res[1];
$text[$i] = $res[2];
$str = "['images/fla/".$image[$i]."','','','".$text[$i]."'],"; //here!!!Notice the comma at the end!
echo $str;
$i++;
} ?>
//<--no trailing comma after very last image element!
],
It should be like this:
Code:
var mygallery=new fadeSlideShow({
wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [<?php $q2 = mysql_query("select * from home_flash");
$i = 0;
//initialize the $image and $text here, and also $str
$image= array (); $text= array (); $str= ""; //for strict compliance
while($res = mysql_fetch_array($q2))
{
$image[$i] = $res[1];
$text[$i] = $res[2];
$str .= ($str!== ""? ",": ""). "['images/fla/".$image[$i]."','','','".$text[$i]."']"; //remove the comma here at the end and put a logical condition to check where the commas should be placed
$i++;
}
echo $str;
?>
//<--no trailing comma after very last image element!
],
Last edited by zidaine_38; 03-20-2010 at 06:01 AM.
Reason: Forgot to echo the string! heheh
[COLOR="Red"]Great answer! Can you also help me with my script? I am having the same problem and can't find which comma to delete or a way to correct it. My script reads as follows:
/***********************************************
* Ultimate Fade In Slideshow v2.0- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
***********************************************/
</script>
<script type="text/javascript">
Bookmarks