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! Quote Link to comment 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()); //--------------------------------------------------------- ?> Quote Link to comment 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 Quote Link to comment 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.