Jump to content

Recommended Posts

Hey,

 

I have t he following pagination code where up until yesterday seemed to work fine. I havent changed anything but I seem to be getting the error:

 

Warning: Division by zero in /home/g39197/public_html/drivers.php on line 410

 

Pagination code is below... I have marked line 410.

 

$mysql_connect = new mysqli("localhost", "xxxxx", "xxxxx");
$mysql_connect->select_db('xxxxx');


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

$query = "SELECT count(*) FROM ads WHERE category = Drivers AND validation = 0";
$result = mysqli_query($mysql_connect, $query) or die (mysqli_error($mysql_connect));


$query_data = mysqli_fetch_row($result);
$numrows = $query_data[0];

$rows_per_page = 10;
$lastpage = ceil($numrows/$rows_per_page);


$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

$query = "SELECT * FROM ads WHERE category = 'Drivers' AND validation = 0 ORDER BY '$sortby' $limit";
$result = mysqli_query($mysql_connect, $query) or die (mysqli_error($mysql_connect));





if ($pageno == 1) {
   echo " First Prev ";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>First</a> ";
   $prevpage = $pageno-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>Prev</a> ";
} // if

//echo " ( Page $pageno of $lastpage ) ";

for($i = 1; $i <= $lastpage; $i++){
        if($i == $pageno){
            echo("[".$i."] ");
        }else{
            echo("<a href=\"$PHP_SELF?pageno=$i\">$i</a> ");
        }
    }

if(($numrows % $limit) != 0){    ************************************ LINE 410
        if($i == $pageno){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?pageno=$i\">$i</a> ");
        }
    } 

if ($pageno == $lastpage) {
   echo " Next Last ";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>Next</a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>Last</a> ";
}
}


 

Any ideas? I'm stumped!

Link to comment
https://forums.phpfreaks.com/topic/55949-pagination-divison-by-0-error/
Share on other sites

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.