ineedhelpbigtime Posted January 12, 2009 Share Posted January 12, 2009 I am getting an undefined offset error with this code. It is displaying the 3 rows that it should, but it trys to make a 4th one which is blank. Says undefined offset 3, so I'm guessing the first in the array is number 0. <?php $bdays = array(); while($friendrow = mysql_fetch_array($friendresult)) { $birthdate = "$friendrow[birthday]"; list($BirthYear,$BirthMonth,$BirthDay) = explode("-", $birthdate); $YearDiff = date("Y") - $BirthYear; $MonthDiff = date("m") - $BirthMonth; $DayDiff = date("d") - $BirthDay; // If the birthday has not occured this year if ($MonthDiff == 0 && $DayDiff > - { $bdays[] = $friendrow['userid']; } } for($i=(0);$i<=count($bdays);$i++) { echo count($bdays); print "$bdays[$i]<br>"; } ?> Any ideas? Im sure im making a stupid error here but im new to this. Its a steep learning curve ??? Link to comment https://forums.phpfreaks.com/topic/140456-solved-undefined-offset/ Share on other sites More sharing options...
kenrbnsn Posted January 12, 2009 Share Posted January 12, 2009 The "for" loop should be: <?php echo count($bdays); $x = count($bdays); for($i=0;$i<$x;$i++) { print "$bdays[$i]<br>"; } ?> The first element of an array is index "0", not 1. Ken Link to comment https://forums.phpfreaks.com/topic/140456-solved-undefined-offset/#findComment-735079 Share on other sites More sharing options...
ineedhelpbigtime Posted January 12, 2009 Author Share Posted January 12, 2009 Thanks ken, much appreciated. Link to comment https://forums.phpfreaks.com/topic/140456-solved-undefined-offset/#findComment-735297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.