How can I pass the correct variables in a URL in PHP for my paging?
<p>I am working on paging in PHP</p>

<ul>
<li>I need it to work on any folder so
root/  root/folder1/ 
root/folder1/folder2/ would all work</li>
<li>It should pass the page number
variable for the script to work in
the URL but also retain any other
variables in the URL that may be
present with any amount of variables
passed in tthe URL</li>
</ul>

<p>Here is what I have so far for the link based on being @</p>

<p><strong><a href="http://domain.com/test/paging/index.php?var=cool&amp;var2=coo2l&amp;page=1" rel="nofollow">http://domain.com/test/paging/index.php?var=cool&amp;var2=coo2l&amp;page=1</a></strong>
<hr></p>

<pre><code>$selfurl = "http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])."";
</code></pre>

<p>This would create this:   <strong><a href="http://domain.com/test/paging/" rel="nofollow">http://domain.com/test/paging/</a></strong></p>

<p><hr></p>

<pre><code>$qry_str = $_SERVER['argv'][0];
</code></pre>

<p>This would create this:   <strong>var=cool&amp;var2=coo2l&amp;page=1</strong>
<hr>
So far so good, it works no matter how deep the directory system is and passes ANY and ALL variables that may exist in the pages URL
(NOTE; I know it assumes it is always the index file I will fix that later)</p>

<p>So all of these links below would get passed through my paging links;</p>

<p><a href="http://domain.com/test/paging/?page=1" rel="nofollow">http://domain.com/test/paging/?page=1</a><br />
<a href="http://domain.com/test/paging/?var=coo2l&amp;page=1" rel="nofollow">http://domain.com/test/paging/?var=coo2l&amp;page=1</a>
<a href="http://domain.com/test/paging/?var=cool&amp;var2=coo2l&amp;page=1" rel="nofollow">http://domain.com/test/paging/?var=cool&amp;var2=coo2l&amp;page=1</a></p>

<blockquote>
  <p>Here is the problem, below is an<br />
  example of my <strong>NEXT</strong> and <strong>PREVIOUS</strong> link,  it works<br />
  but the problem is after I go to the<br />
  first page, it will keep adding  </p>
  
  <p><strong>&amp;page=THE-NUMBER-HERE</strong> so when you get to page 3 it  </p>
  
  <p>would be like  </p>
  
  <p><strong>&amp;page=THE-NUMBER-HERE&amp;page=THE-NUMBER-HERE&amp;page=THE-NUMBER-HERE</strong>  </p>
  
  <p>instead of  </p>
  
  <p><strong>&amp;page=THE-NUMBER-HERE</strong></p>
</blockquote>

<p><strong>The links;</strong></p>

<pre><code>&lt;a href="&lt;?PHP echo $selfurl;?&gt;/?&lt;?PHP echo $qry_str;?&gt;&amp;page=&lt;?PHP echo $start-$pagesize;?&gt;" class="bluelinkbold"&gt;Next&lt;/a&gt;

&lt;a href="&lt;?PHP echo $selfurl;?&gt;/?&lt;?PHP echo $qry_str;?&gt;&amp;page=&lt;?PHP echo $start-$pagesize;?&gt;" class="bluelinkbold" &gt;Previous&lt;/a&gt;
</code></pre>

<p><BR><BR></p>

<h2>How can I resolve this path correctly?</h2>

<p><BR></p>
