Jump to content

Pagination error


EchoFool

Recommended Posts

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

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

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.