Jump to content

Recommended Posts

I am very new to php. I am using a php code to use a image directory to fade image in and out. I need to be able to use the same code but for different directories on the same page.

<?
// Global Variables
$image_dir = "$_SERVER[DOCUMENT_ROOT]/trinity_cyclery2011/bmx/images/mirraco"; // directory on server
$image_relative_path = '/trinity_cyclery2011/bmx/images/mirraco'; // path to images relative to script
$file_types = array('jpg','jpeg','gif','png');
$image_time = '4000'; // seconds each image will display (4000 = 4 seconds)

if($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
	$ext_bits = explode(".",$file); // finds file extensions
	foreach($ext_bits as $key => $value){
		if(in_array($value,$file_types)){
			$image_rotation .= '<li><img src="'.$image_relative_path.'/'.$file.'"></li>';
		}		
	}
}
}
closedir($handle);
}

?>
<?
// Global Variables
$image_dir = "$_SERVER[DOCUMENT_ROOT]/trinity_cyclery2011/bmx/images/fitbike"; // directory on server
$image_relative_path = '/trinity_cyclery2011/bmx/images/fitbike'; // path to images relative to script
$file_types = array('jpg','jpeg','gif','png');
$image_time = '4000'; // seconds each image will display (4000 = 4 seconds)

if($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
	$ext_bits = explode(".",$file); // finds file extensions
	foreach($ext_bits as $key => $value){
		if(in_array($value,$file_types)){
			$image_rotation_fit .= '<li><img src="'.$image_relative_path.'/'.$file.'"></li>';
		}		
	}
}
}
closedir($handle);
}

?>

 

and this goes in the document.

 

        

          <script>
$(document).ready(function() { 
$('#image_rotate').innerfade({ 
	speed: 'slow', 
	timeout: 4000, 
	type: 'sequence', 
	containerheight: '220px'
});
});
</script>


<ul id="image_rotate" style="list-style: none;">
<?= $image_rotation; ?>
</ul> 

          





        <script>
$(document).ready(function() { 
$('#image_rotate').innerfade({ 
	speed: 'slow', 
	timeout: 4000, 
	type: 'sequence', 
	containerheight: '220px'
});
});
</script>


<ul id="image_rotate" style="list-style: none;">
<?= $image_rotation_fit; ?>
</ul> 
          

 

any help will be greatly appreciated. Thanks

This isn't a PHP problem. Avoid using the same ID multiple times. You have "#image_rotate" used twice, jQuery is going to confuse itself. If you want to use a layer multiple times make it a class. I would suggest renaming both IDs to something like.

 

<ul id="gallery1">

 

and

 

<ul id="gallery2">

 

Then you should be able to use

$('#gallery1, #gallery2')

in your jQuery script.

I am trying to use what you put but it doesn't seem to work correctly. I know I must be not putting something correctly.

 

Here is what I am putting. I also tried it exactly the way you had it and it didn't work.

<?
// Global Variables
$image_dir = "$_SERVER[DOCUMENT_ROOT]/trinity_cyclery2011/bmx/images/mirraco"; // directory on server
$image_relative_path = '/trinity_cyclery2011/bmx/images/mirraco'; // path to images relative to script
$file_types = array('jpg','jpeg','gif','png');
$image_time = '4000'; // seconds each image will display (4000 = 4 seconds)
$id = ('gallery1');
if($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
	$ext_bits = explode(".",$file); // finds file extensions
	foreach($ext_bits as $key => $value){
		if(in_array($value,$file_types)){
			$image_rotation .= '<li><img src="'.$image_relative_path.'/'.$file.'"></li>';
		}		
	}
}
}
closedir($handle);
}

?>
<?
// Global Variables
$image_dir = "$_SERVER[DOCUMENT_ROOT]/trinity_cyclery2011/bmx/images/fitbike"; // directory on server
$image_relative_path = '/trinity_cyclery2011/bmx/images/fitbike'; // path to images relative to script
$file_types = array('jpg','jpeg','gif','png');
$image_time = '4000'; // seconds each image will display (4000 = 4 seconds)
$id = ('gallery2');
if($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
	$ext_bits = explode(".",$file); // finds file extensions
	foreach($ext_bits as $key => $value){
		if(in_array($value,$file_types)){
			$image_rotation .= '<li><img src="'.$image_relative_path.'/'.$file.'"></li>';
		}		
	}
}
}
closedir($handle);
}

?>

 

and this is on the page.

         <script>  
$(document).ready(function() {   
    $('#image_rotate').innerfade({   
        speed: 'slow',   
        timeout: '4000',   
        type: 'sequence',   
        containerheight: '220px'  
    });  
});  
</script>  
<ul id="gallery1" style="list-style: none outside none;">  
    <?= $image_rotation; ?>  
</ul>  

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.