heartnet07 Posted March 10, 2015 Share Posted March 10, 2015 Please help..I'm newbie in PHP I'm getting this error Warning: mysql_fetch_array() expects parameter 1 to be resource, integer given in C:\xampp\htdocs\Thesis\UBHSOCR\student_list.php on line 178 this is my code thanks <?php $page = (int) $_GET['page']; if ($page < 1) $page = 1; $resultsPerPage = 20; $startResults = ($page - 1) * $resultsPerPage; $numberOfRows = mysql_num_rows(mysql_query("SELECT user.username, student.student_fn, student.student_ln, student.student_mi, section.year, section.section FROM ubhsocr.user INNER JOIN (ubhsocr.section INNER JOIN student ON section.section_id = student.section_id) ON user.user_id = student.user_id where user.type='Student' ORDER BY user.username")); $totalPages = ceil($numberOfRows / $resultsPerPage); $query = mysql_query("SELECT user.username, student.student_fn, student.student_ln, student.student_mi, section.year, section.section FROM ubhsocr.user INNER JOIN (ubhsocr.section INNER JOIN student ON section.section_id = student.section_id) ON user.user_id = student.user_id where user.type='Student' ORDER BY user.username LIMIT $startResults, $resultsPerPage"); while($data = mysql_fetch_array( MYSQL_ASSOC)) { echo'<tr>'; echo '<td class="td_table_fill1">'.'<a class="noline" href="admin_stud_profile.php?id='.$data['username'].'">'.$data['username']." ".'</a>'.'</td>'; echo '<td class="td_table_fill">'.$data['student_fn'].' '.$data['student_mi'].'.'.' '.$data['student_ln'].'</td>'; echo '<td class="td_table_fill">'.$data['section'].'</td>'; echo '<td class="td_table_fill">'.$data['year'].'</td>'; echo '</tr>'; } echo '<a href="student_list.php?page=1">First</a> '; if($page > 1) echo '<a href="student_list.php?page='.($page - 1).'">Back</a> '; for($i = 1; $i <= $totalPages; $i++) { if($i == $page) echo '<strong>'.$i.'</strong> '; else echo '<a href="student_list.php?page='.$i.'">'.$i.'</a> '; } if ($page < $totalPages) echo '<a href="student_list.php?page='.($page + 1).'">Next</a> '; echo '<a href="student_list.php?page='.$totalPages.'">Last</a>'; ?> Quote Link to comment Share on other sites More sharing options...
jcbones Posted March 10, 2015 Share Posted March 10, 2015 In short, your query is failing. replace $query = mysql_query("SELECT user.username, student.student_fn, student.student_ln, student.student_mi, section.year, section.section FROM ubhsocr.user INNER JOIN (ubhsocr.section INNER JOIN student ON section.section_id = student.section_id) ON user.user_id = student.user_id where user.type='Student' ORDER BY user.username LIMIT $startResults, $resultsPerPage"); with $query = mysql_query("SELECT user.username, student.student_fn, student.student_ln, student.student_mi, section.year, section.section FROM ubhsocr.user INNER JOIN (ubhsocr.section INNER JOIN student ON section.section_id = student.section_id) ON user.user_id = student.user_id where user.type='Student' ORDER BY user.username LIMIT $startResults, $resultsPerPage") or trigger_error(mysql_error()); Make sure: To of script <?php error_reporting(-1); ini_set('display_errors','1'); This should tell you why the query is failing. PS. You should be using the mysqli or PDO libraries, and not mysql for compatibility and security issues. Quote Link to comment Share on other sites More sharing options...
jcbones Posted March 10, 2015 Share Posted March 10, 2015 Actually, scratch that. Your issue is here: while($data = mysql_fetch_array( MYSQL_ASSOC)) You are using the mysql_fetch_array() function wrong. You would pass it the statement handle(in your case $query), not a constant value. To get the associated value, use the mysql_fetch_assoc() function. 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.