Pagination in PHP - page links
<p>Thank you everyone who helped me yesterday with this new to me topic.
I've tried to write code myself, and it works fine for the first page.
However, when I click any of the page links, I get this:</p>

<blockquote>
  <p>The requested URL /headfirst_phpmysql/guitarwars/index.php&amp;page=3 was not found on this server.</p>
  
  <p>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.</p>
</blockquote>

<p>Here is my entire PHP:</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Guitar Wars - High Scores&lt;/title&gt;
&lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;Guitar Wars - High Scores&lt;/h2&gt;
&lt;p&gt;Welcome, Guitar Warrior, do you have what it takes to crack the high score list? If 

so, just &lt;a href="addscore.php"&gt;add your own score&lt;/a&gt;.&lt;/p&gt;
  &lt;hr /&gt;

&lt;?php
  // This function builds navigational page links based on the current page and the number of pages
  function generate_page_links($cur_page, $num_pages) {
  $page_links = '';

  // If this page is not the first page, generate the "Previous" link
  if ($cur_page &gt; 1) {
  $page_links .= '&lt;a href = "' . $_SERVER['PHP_SELF'] .
  '&amp;page=' . ($cur_page - 1) . '"&gt;&lt;-&lt;/a&gt;';
  }
  else {
  $page_links .= '&lt;- ';
  }
  // Loop through the pages generating the page number links
  for ($i = 1; $i &lt;= $num_pages; $i++) {
  if ($cur_page == $i) {
  $page_links .= '' . $i;
  }
  else {
  $page_links .= '&lt;a href = "' . $_SERVER['PHP_SELF'] .
  '&amp;page=' . $i . '"&gt; ' . $i . '&lt;/a&gt;';
  }
  }
  // If this page is not the last page, generate the "Next" link
  if ($cur_page &lt; $num_pages) {
  $page_links .= '&lt;a href = "' . $_SERVER['PHP_SELF'] .
  '&amp;page=' . ($cur_page + 1) . '"&gt;-&gt;&lt;/a&gt;';
  }
  else {
  $page_links .= '-&gt;';
  }

  return $page_links;
  }

  // Calculate pagination information
  $cur_page = isset($_GET['page']) ? $_GET['page'] : 1;

  // Number of results per page
  $results_per_page = 5;

  // Compute the number of the first row on the page
  $skip = (($cur_page - 1) * $results_per_page);

  require_once('appvars.php');
  require_once('connectvars.php');

  // Connect to the database 
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 

 // Retrieve the score data from MySQL
  $query = "SELECT * FROM guitarwars WHERE approved = 1 ORDER BY score DESC, date ASC";
  $data = mysqli_query($dbc, $query);
  $total = mysqli_num_rows($data);
  $num_pages = ceil($total / $results_per_page);

  // Query again to get just the subset of results
  $query = $query . " LIMIT $skip, $results_per_page";
  $data = mysqli_query($dbc, $query);
  // Loop through the array of score data, formatting it as HTML 
  echo '&lt;table&gt;';
  $i = 0;
  while ($row = mysqli_fetch_array($data)) { 
    // Display the score data
    if ($i == 0) {
      echo '&lt;tr&gt;&lt;td colspan="2" class="topscoreheader"&gt;Top Score: ' . $row['score'] . '&lt;/td&gt;&lt;/tr&gt;';
    }
    echo '&lt;tr&gt;&lt;td class="scoreinfo"&gt;';
    echo '&lt;span class="score"&gt;' . $row['score'] . '&lt;/span&gt;&lt;br /&gt;';
    echo '&lt;strong&gt;Name:&lt;/strong&gt; ' . $row['name'] . '&lt;br /&gt;';
    echo '&lt;strong&gt;Date:&lt;/strong&gt; ' . $row['date'] . '&lt;/td&gt;';
    if (is_file(GW_UPLOADPATH . $row['screenshot']) &amp;&amp; filesize(GW_UPLOADPATH . $row['screenshot']) &gt; 0) {
      echo '&lt;td&gt;&lt;img src="' . GW_UPLOADPATH . $row['screenshot'] . '" alt="Score image" /&gt;&lt;/td&gt;&lt;/tr&gt;';
    }
    else {
      echo '&lt;td&gt;&lt;img src="' . GW_UPLOADPATH . 'unverified.gif' . '" alt="Unverified score" /&gt;&lt;/td&gt;&lt;/tr&gt;';
    }
    $i++;
  }
  echo '&lt;/table&gt;';

  // Generate navigational page links if we have more than one page
  if ($num_pages &gt; 1) {
  echo generate_page_links($cur_page, $num_pages);
  }
  mysqli_close($dbc);
?&gt;

&lt;/body&gt; 
&lt;/html&gt;
</code></pre>
