heshan Posted August 29, 2012 Share Posted August 29, 2012 Hi All, When i try to run following PHP page, an error message displayed like this. According to my knowledge an undefined offset means the index does not exist. what could have been the possible reason in case of below code? Undefined offset: 0 in C:\wamp\www\student payments reports\studentsPaymentForm.php on line 171. Undefined offset: 0 in C:\wamp\www\student payments reports\studentsPaymentForm.php on line 172. Undefined offset: 0 in C:\wamp\www\student payments reports\studentsPaymentForm.php on line 173. <?PHP //get class id $class_id=''; if($stream!=null){ $query1="select class_id from class where class_name='$class' and grade_id='$grade' and stream='$stream'"; }else{ $query1="select class_id from class where class_name='$class' and grade_id='$grade'"; } $result1=mysql_query($query1) or die (mysql_error()); while($row1=mysql_fetch_array($result1)){ $class_id=$row1['class_id']; } //accoding to the class id gets admission numbers $query1="select admission_no from student_class where class_id='$class_id' and year='$year'"; $result1=mysql_query($query1) or die (mysql_error()); $x=0; while($row1=mysql_fetch_array($result1)){ $x++; $admission_id[$x]=$row1['admission_no']; } //according to the admission number gets amount id for ($i=1;$i<=$x;$i++) { $query1 = "select amount_id from payment where admisssion_no='".$admission_id[$i]."'"; $result1=mysql_query($query1) or die (mysql_error()); while($row1=mysql_fetch_array($result1)){ $amount_i[$i]=$row1['amount_id']; } } //according to the amount id gets payment values for ($j=1;$j<=$x;$j++) { $query1 = "select payment_value from payment_amount where amount_id='".$amount_i[$j]."' AND date LIKE '$year-%'"; $result1=mysql_query($query1) or die (mysql_error()); while($row1=mysql_fetch_array($result1)){ $payment_values[$j]=$row1['payment_value']; } } //according to the payment values gets name with initials for ($l=1;$l<=$x;$l++) { $query1 = "select name_with_initial from student_info where admission_no='".$admission_id[$l]."'"; $result1=mysql_query($query1) or die (mysql_error()); while($row1=mysql_fetch_array($result1)){ $name_with_initials[$l]=$row1['name_with_initial']; } } for($y=0;$y<=$x;$y++){ echo "<tr>"; // Lines showing errors echo "<td>".$admission_id[$y]."</td>"; echo "<td>".$name_with_initials[$y]."</td>"; echo "<td>".$payment_values[$y]."</td>"; echo "</tr>"; } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 29, 2012 Share Posted August 29, 2012 You start the loops at 1 when assigning, then start at 0 when reading. So, clearly, nothing is set at the index of 0. Quote Link to comment Share on other sites More sharing options...
heshan Posted August 29, 2012 Author Share Posted August 29, 2012 Thanks a lot jesirose for pointing me out the error...now i have fixed it.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.