EchoFool Posted February 18, 2008 Share Posted February 18, 2008 I have attempted my first pagination script but get an error on some syntax... was wondering if you would be kind enough to show me what i have done wrong.. My error is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-15,15' at line 1 This is my pagination script: <?php $Check = mysql_query("SELECT ThreadStarter FROM forums WHERE ThreadID='$Thread' && Catergory='$Catergory'") Or die(mysql_error()); //pagination test $rows_per_page = 15; $TotalRows = mysql_num_rows($Check); $LastPage = ceil($TotalRows/$rows_per_page); //numeric validation $Page = (int)$Page; if ($Page < 1) { $Page = 1; } elseif ($Page > $LastPage) { $Page = $LastPage; } $Limit = 'LIMIT ' .($Page - 1) * $rows_per_page .',' .$rows_per_page; $query = mysql_query("SELECT ThreadStarter,ThreadName,LockedSticky FROM forums WHERE ThreadID='$Thread' && Catergory='$Catergory' $Limit") Or die(mysql_error()); //--------------------------------------------------------- ?> Help is much appreciated! Link to comment https://forums.phpfreaks.com/topic/91706-pagination-error/ Share on other sites More sharing options...
Chris92 Posted February 18, 2008 Share Posted February 18, 2008 Try this: <?php $Check = mysql_query("SELECT ThreadStarter FROM forums WHERE ThreadID='$Thread' && Catergory='$Catergory'") Or die(mysql_error()); //pagination test $rows_per_page = 15; $TotalRows = mysql_num_rows($Check); $LastPage = ceil($TotalRows/$rows_per_page); //numeric validation $Page = (int)$Page; if ($Page < 1) { $Page = 1; } elseif ($Page > $LastPage) { $Page = $LastPage; } $Limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; if($Limit < 0) { $Limit = 'LIMIT 0, 15'; } $query = mysql_query("SELECT ThreadStarter,ThreadName,LockedSticky FROM forums WHERE ThreadID='$Thread' && Catergory='$Catergory' $Limit") Or die(mysql_error()); //--------------------------------------------------------- ?> Link to comment https://forums.phpfreaks.com/topic/91706-pagination-error/#findComment-469708 Share on other sites More sharing options...
EchoFool Posted February 18, 2008 Author Share Posted February 18, 2008 Ok thats fixed the error! Thankyou Chris.. lets just hope it works SOLVED Link to comment https://forums.phpfreaks.com/topic/91706-pagination-error/#findComment-469711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.