Ajax requests, pages, and Code to figure data range for diff. cats
<p>Okay, So I will get a little more specific (since my last question).</p>

<p>Basically, I have a pagination page - and there are three display categories BUT only 50 items display per pagination page. So, you could get all of a single category taking up a page, or a combination of different categories - but they can't exceed 50 items per page. Once a new category is reached, a header displays, then the associated items. I am having trouble figuring out the math to append to the ajax call to request each of the categories. For example, lets say you search for <em>linen</em>. And lets say you get back a total of 329 matches spread across the three categories as shown below. Now, I will be handed back some <em>data</em> so I will know certain things up front even though I will only query 50 items at a time.</p>

<p>A. Search for <em>linen</em> :</p>

<p><strong>Base data</strong></p>

<pre><code>Total Items: 129
Category1 has 111 items
Category2 has 101 items
Category3 has 17 items
</code></pre>

<p>so, on <strong>page 1</strong> you would see:</p>

<pre><code>CATEGORY 1 HEADER
... list of the 50 items ...
</code></pre>

<p>B. User clicks "next"
(since we are still in the category 1 threshold), we'd get the second set of 50.</p>

<p><strong>Page 2:</strong></p>

<pre><code>CATEGORY 1 HEADER
List of next 50 items
</code></pre>

<p>C. USER clicks "next"
(we broke category 1 total, so now we reach into category 2).</p>

<p><strong>Page 3:</strong></p>

<pre><code>CATEGORY 1 HEADER
List of 11 items

CATEGORY 2 HEADER
List of 39 category 2 items
</code></pre>

<p>etc..</p>

<p>The issue I am having, that without doing a ton of if/else/||/&amp;&amp; etc.. is there a nifty algorithm that will give me ranges so on the "next" page click I can have ajax params request ranged for the backend.</p>

<p>ie.. so for the third next page click - (has both category1 and category 2, as shown above).
In a perfect world my Ajax would fire two calls, one for category1 and one for category 2, like so. Of course, if the list of 50 spanned all three cats in full, then three calls would be made.</p>

<pre><code>/category1?rows=11&amp;start=101
/category2?rows=39&amp;start=1
</code></pre>

<p>something like that. So I know I want 11 items from first ajax call with the start of 101. The backend, I assume, will know the range is 101-111 etc..</p>

<p>I hope I am succinct enough here to supply my needs. The solution seems very mathish.</p>

<p>I was working along the lines of, just penciling things...</p>

<p>(category1 - (max x (currPage - 1)) / max >= 1 --> request 50 category 1 if true;</p>

<p>(category1 - (max x (currPage - 1)) / max &lt; 1 --> request the Modulus amount and then start into category2</p>

<p>We use jquery.</p>
