heshan Posted August 29, 2012 Share Posted August 29, 2012 Hi All, I want to retrieve time table data for viewing purposes for the teachers. Here i have created this form, but it throws 2 types errors. 1). Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\teachers\sudent attendance\tviewStudentAttendanceForm.php on line 151 2.) Notice: Uninitialized string offset: 1 in C:\wamp\www\teachers\sudent attendance\tviewStudentAttendanceForm.php on line 163. I know error 1 usually comes when a user try to reuse an existing variable ($result) inside a while loop. But i have fixed it by giving different names. But still the error displays as it is. I have no idea about the error number 2. Please help me out. <?php $state_i=''; $state_id=''; if($stream!=null){ $query1="select class_id from class where class.grade_id='$grade' and class.class_name='$class' and class.stream='$stream'"; }else{ $query1="select class_id from class where class.grade_id='$grade' and class.class_name='$class'"; } $result1=mysql_query($query1); while($row1=mysql_fetch_array($result1)){ $class_id=$row1['class_id']; } $query="SELECT student_class.admission_no,student_info.name_with_initial FROM student_info INNER JOIN student_class ON student_info.admission_no=student_class.admission_no where student_class.year='$year' and student_class.class_id='$class_id'"; $result=mysql_query($query); $x=0; while($row=mysql_fetch_array($result)){ $x++; $admission_id[$x]=$row['admission_no']; $name[$x]=$row['name_with_initial']; } for ($i=1;$i<=$x;$i++) { $query2 = "select attendance_state.state,attendance_state.state_id from attendance_state inner join attendance on attendance_state.state_id=attendance.state_id where attendance.admission_no='".$admission_id[$i]."' and attendance.date='$date'"; $result2=mysql_query($query2); //Line 151 while($row2=mysql_fetch_array($result2)){ $state_i[$i]=$row2['state']; $state_id[$i]=$row2['state_id']; }} for($y=1;$y<=$x;$y++){ echo"<tr>"; echo"<td width='127' align='center'>".$admission_id[$y]."</td>"; echo"<td width='274' align='center'>".$name[$y]."</td>";?> //Line 163 <td width='103' align='center'><?php if($state_i[$y]=='pf'){ echo "present fullday";}if($state_i[$y]=='ph'){ echo "present halfday";}if($state_i[$y]=='ab'){ echo "absent";} ?></td><?PHP echo"</tr>"; } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 29, 2012 Share Posted August 29, 2012 A query is failing, and since you don't have any logic in place to make sure the queries succeed, you're passing a boolean FALSE to mysql_fetch_array(). Echoing (or logging) the error from mysql_error() and the query string that caused the error would be a good place to start. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 29, 2012 Share Posted August 29, 2012 The first error is being cause by your query failing. Look at the examples on mysql_query, and you'll want to print the error and the SQL so you can debug what's wrong with your query. Edit: On preview, what pikachu said. I'm just going to leave this here for the link to the examples. Quote Link to comment Share on other sites More sharing options...
heshan Posted August 29, 2012 Author Share Posted August 29, 2012 It says " Unknown column 'attendance_state.state' in 'field list' " in the following query. But i do not see anything wrong here. My attendance_state table looks like this. attendance_state (state_id, state) $query2 = "select attendance_state.state_id,attendance_state.state from attendance_state inner join attendance on attendance_state.state_id=attendance.state_id where attendance.admission_no='".$admission_id[$i]."' and attendance.date='$date'"; $result2=mysql_query($query2) or die (mysql_error()); 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.