Solarpitch Posted June 17, 2007 Share Posted June 17, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/55949-pagination-divison-by-0-error/ Share on other sites More sharing options...
harristweed Posted June 17, 2007 Share Posted June 17, 2007 $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; if(($numrows % $limit) != 0) I don't think you can divide a number by a text string! Quote Link to comment https://forums.phpfreaks.com/topic/55949-pagination-divison-by-0-error/#findComment-276353 Share on other sites More sharing options...
Solarpitch Posted June 17, 2007 Author Share Posted June 17, 2007 I am not too sure if that would matter . . $limit is holding the value of that string so I dont see how that could affect it. I know you cant divide by 0, but I dont see how the code is preforming that. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/55949-pagination-divison-by-0-error/#findComment-276357 Share on other sites More sharing options...
AndyB Posted June 17, 2007 Share Posted June 17, 2007 $limit is a string. It has a numerical value of zero (same as any other string). In your code $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; so $limit is going to be a string like 'LIMIT 20,10' Quote Link to comment https://forums.phpfreaks.com/topic/55949-pagination-divison-by-0-error/#findComment-276367 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.