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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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