Jump to content

Self-processing pagination


w3sl3y2003

Recommended Posts

Hi all,

I'm pretty much a noob at php and really need some help if someone is willing and able.

I'd like to create a self-processing form that uses pagination to traverse a database resultset. I've basically nailed the cause of the problem that i have down to the fact that when i try to read the value i store in a hidden field, it's always null.

I've included just a rough skeleton of what i'm trying to do (without the unnecessary db code), to just simulate the problem. This code has the same problem as my original attempt by the way.

**************************PHP*******************************

<html>
<body>
        <br>
        <div>
        Previous news bulletins
        </div>
        <br>
<?php

        $current_index = $_POST['current_index'];

        printPageNumbers(262);
       
        for($i=0; $i<10; $i++)
        {
          print "Current Index = " . $current_index . "<br>";
          $current_index++;
        }
       
        print "-------------------------------";
       
        ?>

        <form name="testform" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
            <input name="current_index" value="<?php print $current_index ?>" type="hidden">
        </form>

<?php

 
  function printPageNumbers($num_rows)
  {
    $remainder_page_size;

    $num_pages = (int) ($num_rows / 10);      //10 is the number of rows per page

    if(($num_rows / 10) > (int)($num_rows / 10))
    {
      $remainder_page_size = $num_rows - (int)($num_rows / 10);
      $num_pages++;
    }


    $page = (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] : 1;

    for($k = 0; $k < $num_pages; $k++)//for($k = ($page - 2); $k <= ($page + 2); $k++)
    {
            echo ($page == $k) ? "[$k] " : "<a href='{$_SERVER['PHP_SELF']}?option=com_news&ItemId=68&page=$k'>$k</a> ";       

    } // end for

    print "<br>";
//    return $page;
  }

?>
</body>
</html>

**************************PHP*******************************

Any and all help is greatly appreciated!
Link to comment
https://forums.phpfreaks.com/topic/28080-self-processing-pagination/
Share on other sites

Thanks for the helping hand ProjectFear!

"so the problem is your not getting a value from the hidden field?" - every time i click on one of the page numbers it the value of $current_index is reset to null.

Unfortunately ; didn't make a difference.

Any ideas?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.