Jump to content

Warning: mysql_fetch_array() expects parameter 1 to be resource, integer given in


Recommended Posts

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>&nbsp';

 

if($page > 1)

echo '<a href="student_list.php?page='.($page - 1).'">Back</a>&nbsp';

 

for($i = 1; $i <= $totalPages; $i++)

{

if($i == $page)

echo '<strong>'.$i.'</strong>&nbsp';

else

echo '<a href="student_list.php?page='.$i.'">'.$i.'</a>&nbsp';

}

 

if ($page < $totalPages)

echo '<a href="student_list.php?page='.($page + 1).'">Next</a> ';

 

echo '<a href="student_list.php?page='.$totalPages.'">Last</a>';

?>

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.

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.

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.