0

This is my code for pagination page. My problem are

(Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\wamp\www\example\pagination.php on line 48) and (Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\wamp\www\example\pagination.php on line 103)

Bold sentences are problem. Any suggestion or solution you may give me for this problem. Thanks :)

    if(isset($_GET['page']))
    {
        $page = $_GET['page'];
    }
    else

 - List item

    {
        $page = 1;
    }

    $sf = ($page-1) * 10;
    $sql = "SELECT d.last_name, d.first_name, d.middle_name, d.title,
                                                        c.clinic_name, c.address, s.work_day, s.start_time, s.end_time, ss.specialization

                                                            FROM schedule s

                                                            LEFT JOIN clinic c on c.clinic_id = s.clinic_id                                                         


                                                            LEFT JOIN doctor_has_specialization dhs on dhs.doctor_id = dhs.doctor_id
                                                            LEFT JOIN specialization ss on ss.specialization_id = dhs.specialization_id
                                                            LEFT JOIN doctor d on d.doctor_id = dhs.doctor_id LIMIT ".$sf.",10";
    $rs = mysql_query($sql,$con);
    //echo $rs;
?>
<html>
    <head>
        <title>Pages</title>
    </head>
    <body>
        <?php
            $sql1 = "SELECT count(d.last_name, d.first_name, d.middle_name, d.title,
                                                        c.clinic_name, c.address, s.work_day, s.start_time, s.end_time, ss.specialization)

                                                            FROM schedule s

                                                            LEFT JOIN clinic c on c.clinic_id = s.clinic_id                                                         


                                                            LEFT JOIN doctor_has_specialization dhs on dhs.doctor_id = dhs.doctor_id
                                                            LEFT JOIN specialization ss on ss.specialization_id = dhs.specialization_id
                                                            LEFT JOIN doctor d on d.doctor_id = dhs.doctor_id";
            $rs1 = mysql_query($sql1,$con);
            ***$row1 = mysql_fetch_row($rs1);***
            $total = $row1[0];
            $tp = ceil($total/10);

            for($i = 1; $i <= $tp; $i++)
            {
                echo "<a href='pagination.php?page=".$i."'>".$i."</a> ";
            }
        ?>
        <table>
            <tr>
                    <th> Middlename </th>
                                        <th> Lastname </th>         
                                        <th> Doctor Title </th>                                         
                                        <th> Specialization</th>
                                        <th> Clinic Name</th>
                                        <th> Clinic Address</th>    
                                        <th> Work Day/s</th>    
                                        <th> Start Time</th>    
                                        <th> End Time</th>  
            </tr>
            <?php
                while($row = mysql_fetch_assoc($rs))
                {
            ?>
            <tr>
                <td><?php echo $row['first_name']; ?></td>
                <td><?php echo $row['middle_name']; ?></td>
                <td><?php echo $row['last_name']; ?></td>
                <td><?php echo $row['title']; ?></td>
                <td><?php echo $row['specialization']; ?></td>
                <td><?php echo $row['clinic_name']; ?></td>
                <td><?php echo $row['address']; ?></td>
                <td><?php echo $row['work_day']; ?></td>
                <td><?php echo $row['start_time']; ?></td>
                <td><?php echo $row['end_time']; ?></td>

            </tr>
            <?php
                }
            ?>
        </table>
        <?php
            $sql1 = "SELECT count(d.last_name, d.first_name, d.middle_name, d.title,
                                                        c.clinic_name, c.address, s.work_day, s.start_time, s.end_time, ss.specialization)

                                                            FROM schedule s

                                                            LEFT JOIN clinic c on c.clinic_id = s.clinic_id                                                         


                                                            LEFT JOIN doctor_has_specialization dhs on dhs.doctor_id = dhs.doctor_id
                                                            LEFT JOIN specialization ss on ss.specialization_id = dhs.specialization_id
                                                            LEFT JOIN doctor d on d.doctor_id = dhs.doctor_id";
            $rs1 = mysql_query($sql1,$con);
            **$row1 = mysql_fetch_row($rs1);**
            $total = $row1[0];
            $tp = ceil($total/10);

            for($i = 1; $i <= $tp; $i++)
            {
                echo "<a href='pagination.php?page=".$i."'>".$i."</a> ";
            }
        ?>
    </body>
</html>
Flot2011
  • 4,391
  • 2
  • 39
  • 57
LouiseF
  • 11

3 Answers3

2

I think your query return null (no results ), you can bypass that using while loop

 while($row=mysql_fetch_array($rs1)) {
      //do your stuff here
   }
JohnTaa
  • 2,662
  • 2
  • 14
  • 15
0

You have an SQL problem, and you need to boil down your problem to only a few lines so that we have to debug only the problem. However, I will help you as best I can on this:

If the mysql query fails, it will not return a result resource, but a boolean, therefore you can run your query as such to get more information:

$res = mysql_query($query) or die( mysql_error() );
DusteD
  • 1,350
  • 9
  • 14
0

Substitute any parameter passed to function "COUNT" to just one value, o "*"

SELECT COUNT(*) FROM....
SELECT COUNT(d.last_name) FROM....

or

SELECT COUNT(distinct d.last_name) FROM...

You're getting "Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean " because the functions mysql_query returns "false" value

More info about COUNT() W3Schools COUNT() description

Olvathar
  • 551
  • 3
  • 10