Jump to content

MySQL/PHP Pagination Errors!


Innovati0n

Recommended Posts

I’m new to PHP so I’m just to get to grips with a few things. It's giving me the error shown below.

 

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 '-10, 10' at line 1

 

What I'm trying to make it so is give me some text when nothing is in the MySQL table, such as "No articles just yet". I also don't want any of the buttons to show.

 

<?php
  $table = "news";
  
  $prows = 10;
  $spread = 6;
  
  $page = $_GET['p'];
  
  $query = mysql_query("SELECT * FROM $table ORDER BY id ASC");
  $rows = mysql_num_rows($query);
  
  $lastp = ceil($rows / $prows);
  
  // ###
  
  if (!isset($page)) {
      $page = 1;
  }
  
  if ($page < 1) {
      $page = 1;
  }
  
  if ($page > $lastp) {
      $page = $lastp;
  }
  
  // ###
  
  $page = isset($_GET['p']) ? $_GET['p'] : 1;
  $pn = ($page * $prows) - $prows;
  
  // ALL MY CODE IS HERE!!!!!!!!!!!!

  }
  
  echo("\t<div class=\"pagination_wrapper\">\n");
  
  echo("\t  <div class=\"pagination\">");
  
  // ###
  
  if ($page == 1) {
      echo("");
  } else {
      echo("<a href='index.php?p=1' class=\"pagination\">First</a>");
  }
  
  // ###
  
  if ($page > 1) {
      $prev = $page - 1;
      echo("<a href='index.php?p=$prev' class=\"pagination\">Previous</a>");
  } else {
      echo("");
  }
  
  // ### 
  
  $min = $page - $spread;
  $max = $page + $spread;
  
  if ($min < 1) {
      $dif = 1 - $min;
      $min = 1;
      $max = $max + $dif;
  }
  
  if ($max > $lastp) {
      $dif = $lastp - $max;
      $max = $lastp;
      $min = $min + $dif;
  }
  
  if ($min < 1) {
      $min = 1;
  }
  
  // ###
  
  
  
  for ($i = $min; $i <= $max; $i++) {
      if ($i == $page) {
          echo("<a href='index.php?p=$i' class=\"pagination selected\">$i</a>");
      } else {
          echo("<a href='index.php?p=$i' class=\"pagination\">$i</a>");
      }
  }
  
  // ###
  
  if ($page < $lastp) {
      $next = $page + 1;
      echo("<a href='index.php?p=$next' class=\"pagination\">Next</a>");
  } else {
      echo("");
  }
  
  // ### 
  
  if ($page == $lastp) {
      echo("");
  } else {
      echo("<a href='index.php?p=$lastp' class=\"pagination\">Last</a>");
  }
  
  echo("</div>\n");
  
  echo("\t</div>\n");
  
  // ### 
?>

 

If you could help then it would be amazing, thank you.  :)

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.