Jump to content

Help W/ Pagination Code From Library


ShoeLace1291

Recommended Posts

I need help with this pagination code that I got from the PHP Code Library at PHPFreaks.com. 

 

This is my image moderation section of the admin panel i'm making:

if($manage == 'images'){

$date = date('M j, o H:i:s');
$time = strtotime($date);
$datetime=date('Y-m-d',$time);

           $session = mysql_query("UPDATE img_mod_sessions SET datetime='$datetime' WHERE uid='$uid'") or die("Error: ".mysql_error());


echo "<h1>Image Moderation</h1>";

$sql = mysql_query("SELECT filename,userID,sid FROM recent_files ORDER BY sid DESC LIMIT 10") or die("Pagination: ".mysql_error());

include("functions/pagination.php");

    $pageid        = $_GET['pid'];//Get the pid value

    if(intval($pageid) == 0) $pageid  = 1; 

    $Paging        = new paging();

    $total_records = $Paging->myRecordCount($sql);//count records

    $totalpage     = $Paging->processPaging(12,$pageid);

    $result        = $Paging->startPaging($sql);//get records in the databse

    $links         = $Paging->pageLinks(basename($PHP_SELF));//1234 links

    unset($Paging); 

$numimgs = mysql_num_rows($sql);

if($numimgs == 0){

     echo "No new images have been uploaded since your last image moderation session.";

} else {

     while($fetch=mysql_fetch_array($query)){

          $filename=$fetch["filename"];
          $posterid=$fetch["posterID"];

     $query2 = mysql_query("SELECT username FROM users WHERE uid = '$posterid'") or die("Error: ".mysql_error());

            $u=mysql_fetch_array($query2);

               $postername=$u["username"];

         echo "<a href='image.php?img=$filename'><img src='uploads/$filename' alt='$filename' width='50' height='50' border='0'></a><br>Posted by $postername<br><br>";

     }

  }

}

 

This is functions/pagination.php:

<? class paging
{
var $pRecordCount;
var $pStartFile;
var $pRowsPerPage;
var $pRecord;
var $pCounter;
var $pPageID;
var $pShowLinkNotice;
function processPaging($rowsPerPage,$pageID)
{
	       $record = $this->pRecordCount;
		   if($record >=$rowsPerPage)
		    	$record=ceil($record/$rowsPerPage);
		   else
				$record=1;
			if(empty($pageID) or $pageID==1)
			{
				$pageID=1;
				$startFile=0;
			}
			if($pageID>1)
			$startFile=($pageID-1)*$rowsPerPage;
			$this->pStartFile   = $startFile;
			$this->pRowsPerPage = $rowsPerPage;
			$this->pRecord      = $record;
			$this->pPageID      = $pageID;
			return $record;
}
function myRecordCount($query)
{
	$rs      			= mysql_query($query) or die(mysql_error()."<br>".$query);
	$rsCount 			= mysql_num_rows($rs);
	$this->pRecordCount = $rsCount;
	unset($rs);
	return $rsCount;
}
function startPaging($query)
{
	$query    = $query." LIMIT ".$this->pStartFile.",".$this->pRowsPerPage;
	$rs       = mysql_query($query) or die(mysql_error()."<br>".$query);
	return $rs;
}
function pageLinks($url)
{
	$this->pShowLinkNotice = " ";
	if($this->pRecordCount>$this->pRowsPerPage)
	{		
		$this->pShowLinkNotice = "Page ".$this->pPageID. " of ".$this->pRecord;
		//Previous link
		if($this->pPageID!==1)
		{
		$prevPage = $this->pPageID - 1;
		$link = "<a href=\"$url?$pid=1&mid=$ltype&cid=$catid\" class=\"$cssclass\">|<<</a>";
		$link .= "<a href=\"$url?$pid=$prevPage&mid=$ltype&cid=$catid\" class=\"$cssclass\"><<</a>     ";
		}
		//Number links 1.2.3.4.5.
		for($ctr=1;$ctr<=$this->pRecord;$ctr++)
		{	
			if($this->pPageID==$ctr)
			$link .=  " <a href=\"$url&pid=$ctr\" style=\"font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#F5E000\"><b>$ctr</b></a>";
			else
			$link .= " <a href=\"$url&pid=$ctr\" style=\"font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#F5E000\">$ctr</a>";
		}
		//Previous Next link
		if($this->pPageID<($ctr-1))
		{
		$nextPage = $this->pPageID + 1;
		$link .= "     <a href=\"$url?$pid=$nextPage&mid=$ltype&cid=$catid\" class=\"$cssclass\">>></a>";	
		$link .="<a href=\"$url?$pid=".$this->pRecord."&mid=$ltype&cid=$catid\" class=\"$cssclass\">>>|</a>";
		}
		return $link;
	}			
}

}
?>

 

I am getting a MySQL Syntax error that says 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 'Resource id #10' at line 1

Resource id #10.  I am guessing it is in pagination.php since only that file uses that type of error output(with the resource id).  I have no idea why it's doing this.  Thanks for any help in advance.

Link to comment
Share on other sites

$total_records = $Paging->myRecordCount($sql);//count records

 

You're sending an already completed query to be re-run, the OOP will run it for you.

 

Change:

 

$sql = mysql_query("SELECT filename,userID,sid FROM recent_files ORDER BY sid DESC LIMIT 10") or die("Pagination: ".mysql_error());

 

To:

 

$sql = "SELECT filename,userID,sid FROM recent_files ORDER BY sid DESC LIMIT 10")

Link to comment
Share on other sites

Ok, now I'm getting this error: 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 'LIMIT 0,12' at line 1

SELECT filename,userID,sid FROM recent_files ORDER BY sid DESC LIMIT 10 LIMIT 0,12

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.