sharke Posted November 22, 2009 Share Posted November 22, 2009 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 #14' at line 1 <?php if (isset($_GET['id']) && isnum($_GET['id'])){ if(!isset($_GET['page'])){ $page = 1; } else { $page = (int)$_GET['page']; } $per_page = 15; $x = (($page * $per_page) - $per_page); codee........... $result = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT $x, $per_page"); other code ....... $total_result = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM comments WHERE img_id='".$_GET['id']."'"),0); $total_per_page = ceil($total_result / $per_page); echo "<ul id='nav'>"; if($page > 1){ $prev = ($page - 1); echo "<li><a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">".PREVPAGE.</a></li>"; } for($i = 1; $i <= $total_per_page; $i++){ if(($page) == $i){ echo "<li><small style='color:#2d91bb;font-weight:bold;font-size:12px'>".$i."</small></li> "; } else { echo "<li><a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a></li> "; } } if($page < $total_per_page){ $next = ($page + 1); echo "<li><a href=\"".$_SERVER['PHP_SELF']."?page=$next\">".NEXTPAGE."</a></li>"; } } Link to comment https://forums.phpfreaks.com/topic/182558-pagination-help/ Share on other sites More sharing options...
Garethp Posted November 22, 2009 Share Posted November 22, 2009 Around where it spits out the error, put echo "Mysql Error: " . mysql_error(); Link to comment https://forums.phpfreaks.com/topic/182558-pagination-help/#findComment-963541 Share on other sites More sharing options...
sharke Posted November 22, 2009 Author Share Posted November 22, 2009 $result = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT $x, $per_page"); if (!$result) {echo "Mysql Error: " . mysql_error();} there is id before pagination -> images.php?id=5 Link to comment https://forums.phpfreaks.com/topic/182558-pagination-help/#findComment-963547 Share on other sites More sharing options...
sharke Posted November 23, 2009 Author Share Posted November 23, 2009 i paste code where i get error, can someone help me... $result = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT $x, $per_page"); if (!$result) {echo "Mysql Error: " . mysql_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 'Resource id #14' at line 1 Link to comment https://forums.phpfreaks.com/topic/182558-pagination-help/#findComment-963560 Share on other sites More sharing options...
sharke Posted November 23, 2009 Author Share Posted November 23, 2009 On second pagination i get 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 'Resource id #15' at line 1 what's wrong here <?php if (isset($_GET['id']) && isnum($_GET['id'])){ $img = $_GET['id']; $recordsPerPage = 10; if (!isset($_GET['pagenum'])){ $_GET['pagenum'] = 0; } //Get total records $query = "SELECT COUNT(*) as total FROM comments WHERE img_id = '".$img."'"; $result = mysql_query($query) or die(mysql_error()); $totalRecords = mysql_result($result, 0, 'total'); //Determine total pages $totalPages = ceil($totalRecords/$recordsPerPage); //Determine current page $currentPage = (int) $_GET['pagenum']; if ($currentPage < 1) { $currentPage = 1; } else if ($currentPage>$totalPages) { $currentPage = $totalPages; } //Get records for current page $start = ($currentPage-1)*$recordsPerPage; $query = "SELECT * FROM comments WHERE img_id = '".$img."' LIMIT {$start}, {$recordsPerPage}"; $result = mysql_query($query) or die(mysql_error()); //Create page navigation section $pageList = array();; if ($currentPage>1) { $pageList[] = "<a href='?pagenum=1'><<</a>"; $pageList[] = "<a href='?pagenum=".($currentPage-1)."'>< Previous Page</a>"; } for($page=1; $page<=$totalPages; $page++) { $pageList[] = ($currentPage==$page) ? "<b>[{$page}]</b>" : "<a href='?page={$page}'>{$page}</a>"; } if ($currentPage<$totalPages) { $pageList[] = "<a href='?pagenum=".($currentPage+1)."'>Next Page ></a>"; $pageList[] = "<a href='?pagenum={$totalPages}'><<</a>"; } $pageNav = implode(' ', $pageList); echo $pageNav; }?> Link to comment https://forums.phpfreaks.com/topic/182558-pagination-help/#findComment-963590 Share on other sites More sharing options...
sharke Posted November 23, 2009 Author Share Posted November 23, 2009 Topic Solved! Link to comment https://forums.phpfreaks.com/topic/182558-pagination-help/#findComment-963598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.