[SOLVED] I Want to get rid of this Warning: Undefined offset

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

[SOLVED] I Want to get rid of this Warning: Undefined offset

Post by dimitris »

Can anyone explain me what is
Warning: Undefined offset: 2 in /home/blabla.bla/www/main.php on line 131


and how can i avoid it?

My script works fine but i want to get rid of that warning

of course without changing anything in php.ini

I have one page where i tick checkboxes with the name selectdb[]

and then i have the script:

Code: Select all

while($selected_dbї$i]!=''){
echo'<p align="center"><b>'.$selected_db&#1111;$i].'</b></p>';
$i++;
&#125;
Thanks a lot guys!
Last edited by dimitris on Wed Jul 28, 2004 4:55 am, edited 1 time in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

change while condition to isset($selected_db[$i]):

Code: Select all

while(isset($selected_db[$i])) {
  echo '<p align="center"><b>' . $selected_db[$i] . '</b></p>'; 
  $i++; 
}
or

Code: Select all

foreach($selected_db as $db) 
  echo '<p align="center"><b>' . $db . '</b></p>';
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

Post by dimitris »

Thanks! It worked and was so simple!
Post Reply