ShoeLace1291 Posted June 3, 2007 Share Posted June 3, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/54076-help-w-pagination-code-from-library/ Share on other sites More sharing options...
chigley Posted June 3, 2007 Share Posted June 3, 2007 $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") Quote Link to comment https://forums.phpfreaks.com/topic/54076-help-w-pagination-code-from-library/#findComment-267356 Share on other sites More sharing options...
ShoeLace1291 Posted June 4, 2007 Author Share Posted June 4, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54076-help-w-pagination-code-from-library/#findComment-267642 Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 If you look at your query, first you say "select the first ten rows" then straight after you say "select the first twelve rows"! You can only limit by one value: so either LIMIT 10 or LIMIT 12. Quote Link to comment https://forums.phpfreaks.com/topic/54076-help-w-pagination-code-from-library/#findComment-267648 Share on other sites More sharing options...
ShoeLace1291 Posted June 4, 2007 Author Share Posted June 4, 2007 Ok, I'm confused. What do I need to change now? Quote Link to comment https://forums.phpfreaks.com/topic/54076-help-w-pagination-code-from-library/#findComment-267651 Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 Well it depends if you want to select the 10 most recent files or 12 most recent files! Quote Link to comment https://forums.phpfreaks.com/topic/54076-help-w-pagination-code-from-library/#findComment-267654 Share on other sites More sharing options...
ShoeLace1291 Posted June 4, 2007 Author Share Posted June 4, 2007 I want to display the 12 most recent files. Quote Link to comment https://forums.phpfreaks.com/topic/54076-help-w-pagination-code-from-library/#findComment-267657 Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 $sql = "SELECT filename,userID,sid FROM recent_files ORDER BY sid DESC LIMIT 12"; Quote Link to comment https://forums.phpfreaks.com/topic/54076-help-w-pagination-code-from-library/#findComment-267670 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.