How to set an Arrays internal pointer to a specific position? PHP/XML

前端 未结 8 1459
花落未央
花落未央 2020-12-01 01:16

Im trying to build a little site using XML instead of a database.

I would like to build a next and prev button which will work relative to the content I have displa

8条回答
  •  渐次进展
    2020-12-01 01:47

    The internal array pointer is mainly used for looping over an array within one PHP script. I wouldn't recommend using it for moving from page to page.

    For that, just keep track of the page number and the page size (number of items per page). Then, when you're loading another page, you can use them to decide which array items to show. For example:

    $pageNum = $_GET["pageNum"];
    $pageSize = 10;
    $startIndex = ($pageNum - 1) * $pageSize;
    $endIndex = ($startIndex + $pageSize) - 1;
    

    (or something similar)

提交回复
热议问题