用POST定制php中的分页

What I need to do is do a pagination with PHP and Post the clicked a href to PHP_SELF and redesign the page according to it.

Here is some example code:

for ($i = 1; $i <= $pagecount; $i++) {

    if ($i == 1)
        echo "<ul>";

    echo "<li>";
    echo "<input type=\"hidden\" name=\"p\" value=\"". $i ."\">";
    echo "<a href=\"\" onclick=\"document.forms['page'].submit(); return false;\">";
    echo "<span>". $i ."</span></a></li>";
    if ($i == $pagecount)
    echo "</ul>";

}

I am listing the pages by this and what I want is to send only the clicked page number to PHP_SELF but it only sends the p=2 for 2 pages (e.g. $_POST["p"] = 2) since the last variable hidden p is 2. How can I fix this without changing the a href part? My aim is to send the variable and don't want it to be seen in the URL. Thanks in any advance :)

I solved the problem by making the code like this:

for ($i = 1; $i <= $pagecount; $i++) {

    if ($i == 1)
        echo "<ul>";

    echo "<li>";
    echo "<input type=\"hidden\" id=\"p\" name=\"p\">";
?>
<a href="" onclick="document.getElementById('p').value=<?php echo $i ?>; document.forms['page'].submit(); return false;">
<?php
    echo "<span>". $i ."</span></a></li>";
    if ($i == $pagecount)
    echo "</ul>";

}

The a href code doesn't work under php tag. Don't know the exact reason though it must be something related with the getElementById option.