Mysql query paginate multi variable results
<p>I would like to paginate my multi termed sql query in paginated results, page 1 works fine but page 2..previous or next do not pass the variable:</p>

<pre><code>&lt;?php


include "db.inc.php";

if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$start_from = ($page-1) * 15;

$term1 = $_REQUEST['term1'];
$term2 = $_REQUEST['term2'];
$term3 = $_REQUEST['term3'];
$term4 = $_REQUEST['term4'];
$sql ="SELECT * FROM cdrequests WHERE pname  LIKE '%$term1%' AND date LIKE '%$term2%' AND date LIKE '%$term3%' AND dept LIKE '%$term4%' LIMIT $start_from, 15";


$rs_result = mysql_query ($sql);
$num_rows = mysql_num_rows($rs_result);
$query = mysql_query("SELECT * FROM cdrequests WHERE pname  LIKE '%$term1%' AND date LIKE '%$term2%' AND date LIKE '%$term3%' AND dept LIKE '%$term4%'"); 
$number=mysql_num_rows($query); 
print "&lt;font size=\"5\" color=white&gt;&lt;b&gt;CD Requests&lt;/b&gt;&lt;/font&gt; &lt;/P&gt;";


print "&lt;table class=\"table1\"    STYLE=\"word-wrap:break-word;\"   width=1100 border=\"1\"  bordercolor=\"#000000\" bgcolor=\"E6E6E6\" style=\"border-collapse: collapse\"   cellpadding=\"2\" cellspacing=\"1\"&gt; .............
?&gt;

&lt;?php 

$term1 = $_REQUEST['term1'];
$term2 = $_REQUEST['term2'];
$term3 = $_REQUEST['term3'];
$term4 = $_REQUEST['term4'];


$sql = "SELECT COUNT(id) FROM cdrequests WHERE pname  LIKE '%$term1%' AND date LIKE '%$term2%' AND date LIKE '%$term3%' AND dept LIKE '%$term4%'";  
$rs_result = mysql_query($sql); 
$row = mysql_fetch_row($rs_result); 
$total_records = $row[0];
$total_pages = ceil($total_records / 15);


/******  build the pagination links ******/
// range of num links to show
$range = 3;



// if not on page 1, don't show back links
if ($page &gt; 1) {
   // show &lt;&lt; link to go back to page 1
   echo " &lt;a href='search2.php?page=1'&gt;&lt;b&gt;First&lt;/b&gt;&lt;/a&gt; ";
   // get previous page num
   $prev = $page - 1;
   // show &lt; link to go back to 1 page
   echo " &lt;a href='search2.php?page=$prev'&gt;&lt;b&gt;&amp;laquo;&lt;/b&gt;&lt;/a&gt; ";
} // end if 



// loop to show links to range of pages around current page
for ($x = ($page - $range); $x &lt; (($page + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x &gt; 0) &amp;&amp; ($x &lt;= $total_pages)) {
      // if we're on current page...
      if ($x == $page) {
         // 'highlight' it but don't make a link
         echo " &lt;font  size='5' color=yellow&gt;&lt;b&gt; $x &lt;/b&gt;&lt;/font&gt; ";
      // if not current page...
      } else {
         // make it a link
         echo " &lt;a href='search2.php?page=$x'&gt;$x&lt;/a&gt; ";
      } // end else
   } // end if 
} // end for


// if not on last page, show forward and last page links        
if ($page != $total_pages) {
   // get next page
   $next = $page + 1;
    // echo forward link for next page 
   echo " &lt;a href='search2.php?page=$next'&gt;&lt;b&gt;&amp;raquo;&lt;/b&gt;&lt;/a&gt; ";
   // echo forward link for lastpage
   echo " &lt;a href='search2.php?page=$total_pages'&gt;&lt;b&gt;Last&lt;/b&gt;&lt;/a&gt; ";
} // end if
/****** end build pagination links ******/
echo "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font size='4' color=white&gt;Total Records&lt;/font&gt; &lt;font size='5' color=yellow&gt;&lt;b&gt;$number&lt;/b&gt;&lt;/font&gt;";

echo '&lt;/table&gt;';

?&gt;
</code></pre>

<p>not sure what I need to put in the  <code>echo " &lt;a href='search2.php?page=$next'&gt;&lt;b&gt;&amp;raquo;&lt;/b&gt;&lt;/a&gt; ";</code> in order to call the terms</p>

<p>thanks</p>
