472,378 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to fix Undefined offset: error?


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
  2.   for( $i=$start; $i<$start + $itemsPerPage; $i++ ) {
  4.           if(is_file( $src_folder .'/'. $files[$i] ) ) { 
  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>'; 
  12.           } else {
  14.             echo $files[$i];
  16.           }
  18.     }
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

May 16 '11 #1
4 7175
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
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)?


May 17 '11 #3
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
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) {
  3.         if(!in_array($album, $ignore)) {    
  5.            array_push( $albums, $album );
  7.            $caption = substr($album,0,20);
  8.            array_push( $captions, $caption );
  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 );
  14.          }
  16.      }
May 17 '11 #5

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

Similar topics

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...
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...
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...
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...
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...
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...
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?...
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...
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 ), ...
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:...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.