Help with Slideshow

I am getting a syntax error on this code. Can anyone help me? The error happens around line 60.

On this line:

<?php echo getJSRandomized($path_to_images, $image_list, $num_to_rotate); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
  <title>Rotate</title>
<script src="http://www.1stnaz.com/js/dw_rotator.js" type="text/javascript"></script>
<script src="http://www.1stnaz.com/js/dw_random.js" type="text/javascript"></script>

<?php 
$path_to_images = "http://www.1stnaz.com/images/Slides/";  // path to your images 
$num_to_rotate = "ALL"; // number or "ALL" (to rotate all images in directory) 

// returns string to echo into JavaScript images array  
function getJSRandomized($path, $list, $num) { 
    $str = '"'; 
    mt_srand( (double)microtime() * 1000000 ); 
    shuffle($list); 
    if ( $num == "ALL" ) $num = count($list); 
    for ($i=0; $i<$num; $i++) { 
        $str .= $path . $list[$i] . '", "'; 
    } 
    // remove last comma and space 
    $str = substr($str, 0, -3); 
    return $str; 
} 

function getImagesList($path) { 
    $ctr = 0; 
    if ( $img_dir = @opendir($path) ) { 
        while ( false !== ($img_file = readdir($img_dir)) ) { 
            // add checks for other image file types here, if you like 
            if ( preg_match("/(.GIF|.jpg)$/", $img_file) ) { 
                $images[$ctr] = $img_file; 
                $ctr++; 
            } 
        } 
        closedir($img_dir); 
        return $images; 
    } else { 
        return false; 
    } 
} 
?> 

</head>
<body onload="dw_Rotator.start()">
<?php if ( $image_list = getImagesList($path_to_images) ) : ?>

<script type="text/javascript">
/*************************************************************************
    This code is from Dynamic Web Coding at dyn-web.com
    Copyright 2001-5 by Sharon Paine 
    See Terms of Use at dyn-web.com/bus/terms.html
    regarding conditions under which you may use this code.
    This notice must be retained in the code as is!
    
    See full source code at dyn-web.com/scripts/rotate-rand/
*************************************************************************/
var imgList = [
  <?php echo getJSRandomized($path_to_images, $image_list, $num_to_rotate);  ?>
  ];
var rotator1 = new dw_RandRotator(4000); // rotation speed
// images array, width and height of images, transition filter (boolean)
rotator1.setUpImage(imgList, 251, 188, true);
</script>

<?php else : ?>
<!-- image to display if directory listing fails -->
<img src="http://www.1stnaz.com/images/Slides/Slide0.jpg" width="252" height="127" alt="">

<script type="text/javascript">dw_Rotator.start = function() {};</script>

<?php endif; ?>

</body>
</html>


What’s the exact error code?

I am getting the following Error with this code:
Internet Explorer Script Error
An error has occured in the script on this page
Line: 60
Char: 3
Error: Syntax Error
Code: 0

Thanks for your help.
Chris

That’s not a PHP error :wink:
Not sure if it’s a JavaScript error though (looks like it). Check out line 60 of the output HTML.

This is what is at line 60 it’s some PHP code:

<?php echo getJSRandomized($path_to_images, $image_list, $num_to_rotate); ?>

It’s sandwiched in between some Javascript:
var imgList = [

<?php echo getJSRandomized($path_to_images, $image_list, $num_to_rotate); ?>

];

For some reason it doesn’t like it. Anyone have a suggestion?

Well yes, I didn’t ask for the source PHP, but the output HTML :wink:

I have posted the code here (click ok to get past the license:
http://www.1stnaz.com/RandomRotate.html

Thanks for your help.

Ah, now I see the problem: your PHP is not being parsed.
Change the extension of your file to .php.

That removes the error but the pictures don’t rotate.
Here is the new file - http://www.1stnaz.com/RandomRotate.php

Any help would be appreciated. Thanks.

I’m thinking your problem is in the file dw_rotator.js.

We’re not a JavaScript helpdesk though, and I think you should be able to debug this one by yourself as well, if you wrote it yourself (and if you didn’t, please consult the author of the script).

Sponsor our Newsletter | Privacy Policy | Terms of Service