Solarpitch Posted January 9, 2007 Share Posted January 9, 2007 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 Link to comment https://forums.phpfreaks.com/topic/33509-division-by-zero-error-in-pagination-code/ Share on other sites More sharing options...
Barand Posted January 9, 2007 Share Posted January 9, 2007 Either $limit is 0 or has not been set.echo $limit;to check. Link to comment https://forums.phpfreaks.com/topic/33509-division-by-zero-error-in-pagination-code/#findComment-156828 Share on other sites More sharing options...
Solarpitch Posted January 9, 2007 Author Share Posted January 9, 2007 Hi, well heres were I set it[code]$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;[/code]And it prints as[code]LIMIT 0,10[/code]ummmm . . I am still confused ;p Link to comment https://forums.phpfreaks.com/topic/33509-division-by-zero-error-in-pagination-code/#findComment-156831 Share on other sites More sharing options...
awpeacock Posted January 9, 2007 Share Posted January 9, 2007 Well, there's your problem - $limit as being used in the "% limit" clause needs to be the 10. Link to comment https://forums.phpfreaks.com/topic/33509-division-by-zero-error-in-pagination-code/#findComment-156836 Share on other sites More sharing options...
Solarpitch Posted January 9, 2007 Author Share Posted January 9, 2007 Na, dont think it is. The code was the same as when I was developing locally. It worked the other day . . but when I uploaded it onto the server I started to get that message! Link to comment https://forums.phpfreaks.com/topic/33509-division-by-zero-error-in-pagination-code/#findComment-156857 Share on other sites More sharing options...
Solarpitch Posted January 9, 2007 Author Share Posted January 9, 2007 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] 2Warning: Division by zero in /home/public_html/drivers.php on line 337Next LastThats what it looks like Link to comment https://forums.phpfreaks.com/topic/33509-division-by-zero-error-in-pagination-code/#findComment-156865 Share on other sites More sharing options...
Barand Posted January 9, 2007 Share Posted January 9, 2007 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=10I 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_ALLIf 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] Link to comment https://forums.phpfreaks.com/topic/33509-division-by-zero-error-in-pagination-code/#findComment-156892 Share on other sites More sharing options...
Solarpitch Posted January 9, 2007 Author Share Posted January 9, 2007 Worked like a charm. Thanks you very very much :D Link to comment https://forums.phpfreaks.com/topic/33509-division-by-zero-error-in-pagination-code/#findComment-156897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.