473,324 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 7298
Dormilich
8,658 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,658 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

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

Similar topics

1
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still...
2
by: Steven | last post by:
Hi All, I am moving some php code from a Linux machine to a Windows 2000 machine with the code belowe I get the following error : Notice: Undefined offset: 1 in c:\inetpub\wwwroot\test.php on...
3
by: delusion7 | last post by:
I am getting this error "Undefined offset: 9 in C:\Course Technology\1687-5\Chapter.10\UpdateContactInfo.php on line 36" this is the code I am recieving the error on: if...
6
by: nicy12 | last post by:
Hi! my name is Peter. iam working on the php platform. while trying to run and compile a program i get the undefined offset error iam nto much familiar with this error . Please help me . Thanks in...
9
by: simple12 | last post by:
Hello I have a script which have the facility of entering any code to some part of a webpage. I have some problems with it. When i put some code in the script then their is no error shown. When i...
2
by: neridaj | last post by:
Hello, I'm trying to figure out how to get rid of these errors: Notice: Undefined offset: 1 in output_fns.php on line 315 Notice: getimagesize() : Read error! in output_fns.php on line 315...
6
by: raydiamond4u | last post by:
Hello. My name is Raymond. My code is generating the following error: Notice: Undefined offset: 2 in C:\wamp\www\imagegallery\supportfile\include\config.php on line 25 How do i correct the error?...
1
by: atang | last post by:
Hi, I found the code here, it's excately what i am looking for, ie8 give this error "Notice: Undefined offset: 49 in.." which is this line "if ($num_of_chars==$required)", i'm a newbie, i don't know...
1
by: Mary meer | last post by:
i am trying to switch array value but i get this error message: Undefined offset 2 $at=array( array('Title:','title',2,10), array('First Name:','fname',2,10 ), ...
6
by: tbebest | last post by:
Hi , i have a form and it has A problem: i upload my 3 image and it uploaded in definded path but in insert in db filed there are empty: Notice: Undefined offset: 0 in C:\wamp\www Notice:...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.