Jump to content

Division by zero error in pagination code?


Solarpitch

Recommended Posts

Hi Guys,

just wondering why I am getting the following error on line 336 in my code..

error:

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

[code]


$query = "SELECT count(*) FROM ads WHERE class = 'Drivers' AND validation = 1";
$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);


****************************************


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 336
        if($i == $pageno){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?pageno=$i\">$i</a> ");
        }
    } [/code]

Obviously I can see that its saying it cant divide by 0 . . but what do you think is the reason for it? Its just a snippet of pagination code and can post the full if needed..

Cheers guys
Actually . .I just checked the functionality of the code and it works fine. That just must be a warning informing me that I am dividing by 0. Is there anyway to get rid of it?

First Prev [1] 2
Warning: Division by zero in /home/public_html/drivers.php on line 337
Next Last

Thats what it looks like
The numeric value of "LIMIT 0, 10" is zero. Try this and see
[code]
$limit = "LIMIT 0, 10";
echo intval($limit);            //  --> 0
[/code]

As awpeacock said, you need $limit=10


I would guess the error reporting level on you local server isn't reporting warnings whereas the new server is. This doesn't mean there error wasn't there, just that the warning was suppressed.

I recommend that when developing, you set error reporting level to E_ALL

If you think it is functionally correct, I suggest you improve your testing.

[code]
$limit = "LIMIT 0, 10";
$numrows = 1;
$x = ($numrows % $limit);
var_dump($x);        // --> bool(false)  every time it will appear to be 0
[/code]

whereas this is correct
[code]
$limit = 10;
$numrows = 1;
$x = ($numrows % $limit);
var_dump($x);        // --> int(1)
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.