Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello friends,

I am facing following error in my pagination script please help me to solve this.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\lib\author\data.php on line 16

following is my script


db.php

PHP
<?php
mysql_connect("localhost","root","");
mysql_select_db("library");
?>


data.php
PHP
<?php

include('../db.php');
if($_GET['page'])
{
    $page =$_GET['page'];
}
$per_page_num=2;
$offset = ($page-1)* $per_page_num;
$getdata = ("select * from author limit $offset,1");
$checking = mysql_query($getdata);
//if($checking=== FALSE) {
 //   die(mysql_error()); // TODO: better error handling
//}

while ($rows = mysql_fetch_array($checking))
{
    ?>

    <?=$rows['name']?><br/>
    <?php
}
?>


delt.php

PHP
<?php
include("../db.php");

$query = mysql_query("select * from author");
$count = mysql_num_rows($query);
$per_page=1;
$total = ceil($count/$per_page);
?>
<ul id="paginate">
    <?php
    for ($i=1;$i<=$total;$i++)
    {
        ?>
        <li id="<?=$i?>"><?=$i?></li>
    <?php
    }
    ?>
</ul>
<div id="content"></div>
<div id="load"></div>
<script src="../jquery.js" type="text/javascript"></script>
<script>
    $(document).ready(function(){
        function display(){
            $("#load").fadeIn("slow");
            $("#load").html('<img src="https://themarketingoak.files.wordpress.com/2015/07/circle-loading-animation.gif">');
        }
        function hide(){
            $("#load").fadeOut(3000);
        }
        $("#paginate li:first").css({color:"red"});
        display();

        $("#content").load('data.php?page=1',hide());
        $("#paginate li").click(function(){
           display();
            $("#paginate li").css({color:"blue"});
            $(this).css({color:"red"});
            var num=$(this).id;
            $("#content").load('data.php?page='+ num,hide());
        });
    });
</script>
Posted
Comments
Nathan Minier 4-Nov-15 9:17am    
No, you have an issue with your database query or connection. Start there.

1 solution

You have commented out the lines which test the return value of the mysql_query function:
PHP
$checking = mysql_query($getdata);
//if($checking=== FALSE) {
//   die(mysql_error()); // TODO: better error handling
//}

The first result from a Google search[^] for "mysql_fetch_array resource boolean" explains:

A query may fail for various reasons in which case both the mysql_* and the mysqli extension will return false from their respective query functions/methods. You need to test for that error condition and handle it accordingly.

Uncomment those lines, and you'll find that you have an error in your query.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900