daily pastebin goal
8%
SHARE
TWEET

ysql_real_escape_string() expects parameter 2 to be resource

annya Nov 17th, 2014 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. include 'includes/connect.php';
  2. $con = MysqlConnect::getInstance();
  3.  
  4. $adjacents = 3;
  5. $count = $con->select("SELECT COUNT(*) as tot FROM `bsi_news_and_events` ", false);
  6. $total_pages = $count['tot'];
  7. $targetpage = "news_and_events.php";  //your file name  (the name of this file)
  8. $limit = 5;         //how many items to show per page
  9. $page = isset($_GET['page']) ? mysql_real_escape_string($_GET['page']) : 0;
  10. if ($page)
  11.     $start = ($page - 1) * $limit;    //first item to display on this page
  12. else
  13.     $start = 0;
  14. //echo "SELECT * FROM `achiev` ORDER BY `achiev_id`  LIMIT ".$start." , ".$limit." ";
  15. $result = $con->select("SELECT * FROM `bsi_news_and_events` ORDER BY `id` DESC  LIMIT " . $start . " , " . $limit . " ", true);
  16. if ($page == 0)
  17.     $page = 1;     //if no page var is given, default to 1.
  18. $prev = $page - 1;       //previous page is page - 1
  19. $next = $page + 1;       //next page is page + 1
  20. $lastpage = ceil($total_pages / $limit);  //lastpage is = total pages / items per page, rounded up.
  21. $lpm1 = $lastpage - 1;
  22. $pagination = "";
  23. if ($lastpage > 1) {
  24.     $pagination .= "<div class=\"pagination\">";
  25.     //previous button
  26.     if ($page > 1)
  27.         $pagination.= "<a href=\"$targetpage?page=$prev\" > &nbsp; < &nbsp;</a>";
  28.     else
  29.         $pagination.= "<span class=\"disabled\"> &nbsp; < &nbsp; </span>";
  30.  
  31.     //pages    
  32.     if ($lastpage < 7 + ($adjacents * 2)) { //not enough pages to bother breaking it up
  33.         for ($counter = 1; $counter <= $lastpage; $counter++) {
  34.             if ($counter == $page)
  35.                 $pagination.= "<span class=\"current\"> &nbsp; $counter</span>";
  36.             else
  37.                 $pagination.= "<a href=\"$targetpage?page=$counter\"> &nbsp; $counter</a>";
  38.         }
  39.     }
  40.     elseif ($lastpage > 5 + ($adjacents * 2)) { //enough pages to hide some
  41.         //close to beginning; only hide later pages
  42.         if ($page < 1 + ($adjacents * 2)) {
  43.             for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
  44.                 if ($counter == $page)
  45.                     $pagination.= "<span class=\"current\"> &nbsp; $counter</span>";
  46.                 else
  47.                     $pagination.= "<a href=\"$targetpage?page=$counter\"> &nbsp; $counter</a>";
  48.             }
  49.             $pagination.= "...";
  50.             $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
  51.             $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
  52.         }
  53.         //in middle; hide some front and some back
  54.         elseif ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
  55.             $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
  56.             $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
  57.             $pagination.= "...";
  58.             for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
  59.                 if ($counter == $page)
  60.                     $pagination.= "<span class=\"current\"> &nbsp; $counter</span>";
  61.                 else
  62.                     $pagination.= "<a href=\"$targetpage?page=$counter\"> &nbsp; $counter</a>";
  63.             }
  64.             $pagination.= "...";
  65.             $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
  66.             $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
  67.         }
  68.         //close to end; only hide early pages
  69.         else {
  70.             $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
  71.             $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
  72.             $pagination.= "...";
  73.             for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
  74.                 if ($counter == $page)
  75.                     $pagination.= "<span class=\"current\"> &nbsp; $counter</span>";
  76.                 else
  77.                     $pagination.= "<a href=\"$targetpage?page=$counter\"> &nbsp; $counter</a>";
  78.             }
  79.         }
  80.     }
  81.  
  82.     //next button
  83.     if ($page < $counter - 1)
  84.         $pagination.= "<a href=\"$targetpage?page=$next\">&nbsp; > </a>";
  85.     else
  86.  
  87.         $pagination.= "<span class=\"disabled\">&nbsp; > </span>";
  88.     $pagination.= "</div>\n";
  89. }
  90. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top