Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As <code>SimpleXMLElement</code> is a <code>Traversable</code>, you can do the pagination with a <a href="http://php.net/LimitIterator" rel="nofollow noreferrer"><code>LimitItertor</code></a> which ships with PHP.</p> <p>To get the total number of product elements you can use the <code>SimpleXMLElement::count()</code> function.</p> <p>Pagination works like outlined in the hundreds of other questions, I preferable use the <a href="https://gist.github.com/hakre/4469154" rel="nofollow noreferrer"><code>LimitPagination</code> type</a> for it.</p> <p>It takes the current page, the total amount of elements and elements per page as arguments (see as well: <a href="https://stackoverflow.com/a/14184729/367456">PHP 5.2 and Pagination</a>). It also has a helper function to provide the <code>LimitIterator</code>.</p> <p>Example:</p> <pre><code>$products = $xml-&gt;product; // pagination $pagination = new LimitPagination($_GET['page'], $products-&gt;count(), 20); foreach ($pagination-&gt;getLimitIterator($products) as $product) { ... } </code></pre> <p>If you want to output a pager that allows to navigate between the pages, the <code>LimitPagination</code> has more to offer to make that a bit easier, e.g. for just all pages highlighting the current page (here exemplary with brackets):</p> <pre><code>foreach ($pagination-&gt;getPageRange() as $page) { if ($page === $pagination-&gt;getPage()) { // current page printf("[p%d] ", $page); } else { printf("p%d ", $page); } } foreach ($pagination-&gt;getPageRange() as $page) { if ($page === $pagination-&gt;getPage()) { // current page printf("[p%d] ", $page); } else { printf("p%d ", $page); } } </code></pre> <p>Interactive online demo: <a href="http://codepad.viper-7.com/OjvNcO" rel="nofollow noreferrer">http://codepad.viper-7.com/OjvNcO</a><br> Less interactive online demo: <a href="http://eval.in/14176" rel="nofollow noreferrer">http://eval.in/14176</a> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload