469,086 Members | 1,271 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,086 developers. It's quick & easy.

How to fix Undefined offset: error?

3
Hello,

I'm designing a photo gallery for my website, I've followed several tutorials online about how to go about doing this, with great success, I have come up with a set of codes, however I keep getting several error messages when I run my code. Furthermore I'm a beginner at PHP programming so please bare with me.

the error message I get is as follows:

Notice: Undefined offset: 2 in C:\wamp\www\LuxuRay\album.php on line 213

Notice: Undefined offset: 2 in C:\wamp\www\LuxuRay\album.php on line 223

I've gone through my code a million time but cannont find whats wrong with it. So if somebody can take a look at my code and tell me whats wrong I would my much obliged.

My code is as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2.   for( $i=$start; $i<$start + $itemsPerPage; $i++ ) {
  3.  
  4.           if(is_file( $src_folder .'/'. $files[$i] ) ) { 
  5.  
  6.             echo '<div class="thumb">
  7.                     <a href="'. $src_folder .'/'. $files[$i] .'" class="albumpix" rel="albumpix">
  8.                       <img src="'. $src_folder .'/thumbs/t_'. $files[$i] .'" width="'.$thumb_width.'" height="'.$thumb_height.'" alt="" />
  9.                     </a>  
  10.                   </div>'; 
  11.  
  12.           } else {
  13.  
  14.             echo $files[$i];
  15.  
  16.           }
  17.  
  18.     }
  19.  
  20.  
Thats the section of my code that is giving the error. Any help will be much appreciated. I look forward to hearing from somebody :-D

By the way Line 2 = Line 213 and Line 14 = Line 223

Thanks
May 16 '11 #1
4 6916
Dormilich
8,651 Expert Mod 8TB
your $files array has less elements than you expect it to have. make sure that $start + $itemsPerPage is not larger than count($files).
May 17 '11 #2
Kevon
3
Thanks for your reply, I was afraid I would have to wait for days.

How would I check if my $start + $itemsPerPage is not larger than count ($files)?

Thanks

Kev
May 17 '11 #3
Dormilich
8,651 Expert Mod 8TB
How would I check if my $start + $itemsPerPage is not larger than count ($files)?
exactly like that (only in code).
May 17 '11 #4
Kevon
3
now I'm getting another error Notice: Undefined index: in C:\wamp\www\LuxuRay\album.php on line 85

but everything is defined

Expand|Select|Wrap|Line Numbers
  1. foreach($folders as $album) {
  2.  
  3.         if(!in_array($album, $ignore)) {    
  4.  
  5.            array_push( $albums, $album );
  6.  
  7.            $caption = substr($album,0,20);
  8.            array_push( $captions, $caption );
  9.  
  10.            $rand_dirs = glob($mainFolder.'/'.$album.'/thumbs/*.*', GLOB_NOSORT);
  11.          $rand_pic = $rand_dirs[array_rand($rand_dirs)];
  12.            array_push( $random_pics, $rand_pic );
  13.  
  14.          }
  15.  
  16.      }
  17.  
May 17 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by lawrence | last post: by
2 posts views Thread by Steven | last post: by
3 posts views Thread by delusion7 | last post: by
9 posts views Thread by simple12 | last post: by
2 posts views Thread by neridaj | last post: by
1 post views Thread by atang | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.