Jump to content

Undefined offset error in PHP


heshan

Recommended Posts

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>";
}

       ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.