Calculating number of items displayed - pagination This is my first post here and found it through Stack Overflow. I am a web designer but I am currently pulling my hair out over the lack of my mathematical knowledge.
On a site displaying a category, there may be a scenario where a user will put subcategories and products within a parent category.
On these pages (categories) where products are displayed, there is a "showing $N$ to $I$ of $T$ products" message (e.g. "showing 1 to 6 of 10 products").
So I am in a rut about how I am to calculate this to only take into account the products and not the categories.
Here's what I know (variables):


*

*$E =$ the current page number (there can be many pages to split up the view)

*$F =$ the amount of products or subcategories allowed on any 1 page

*$Y =$ the total amount of subcategories being displayed in this category

*$L =$ the total amount of products displayed in this category 
Also the subcategories are always displayed first before the products.
If anyone can help me out or give a push in the right direction, it would be much appreciated.
EDIT
as per the solution below, here is the PHP interpritation:
(valiables are in relation to the post and relating comments)
function f( $x, $f, $y, $l ) {
    return ( ( $x * $f ) - $y < 0 ? 0 : ( ( $x * $f ) - $y > $l ? $l : ( $x * $f ) - $y ) );
}

$n = 1 + f($e-1, $f, $y, $l);
$i = f($e, $f, $y, $l);
echo 'Showing ' . $n .' to ' . $i . ' of ' . $l . ' Products';

 A: When you don't have categories, the number of pages is $\frac{L}{F}$, rounded up to the next whole number.  So if there are 53 products and you display 8 per page, you will need 7 pages.  On page E, you will have objects (E-1)*F+1 to E*F.If you have categories, does each one start on a new page?  Then you just have the same calculation for each category.  If your 53 objects are in categories of 12,23,5, and 13, you would have 2,3,1, and 2 pages, for a total of 8.  You then have to decide whether the showing N to P of M is within the category or over all products.  Is this what you were after?
A: If I understand you correctly, a category can contain two kinds of items: subcategories and products.  Out of those, subcategories are always sorted before products.  On each page, you display (up to) $F$ items, and, for the $E$-th page, you want to know 


*

*$N =$ the total number of products displayed on pages $1$ to $E-1$ plus one, and

*$I =$ the total number of products displayed on pages $1$ to $E$.


Clearly, there are $E$ times $F$ items (products or subcategories) displayed on the pages $1$ to $E$ (unless this would exceed $L+Y$, in which case that's the upper limit).  Out of those, up to $Y$ will be subcategories, so we're left with $EF-Y$ products (unless $EF<Y$, in which case there will be no products on those pages).
So, let's use $f(X)$ to denote the total number of products displayed on pages $1$ to $X$.  Then
$$f(X) = \begin{cases}
0 & \text{if } XF-Y < 0 \\
L & \text{if } XF-Y > L \\
XF-Y & \text{otherwise}.
\end{cases}$$
Using this rule, we can then easily calculate $N = 1 + f(E-1)$ and $I = f(E)$.
(Ps. Note that, if $Y \ge F$, using this rule the first page would carry a message saying "showing $1$ to $0$ of $L$ products".  You may want to have a separate message for the case $I=0$ if there's any chance that it could occur in practice.)
A: 
Also the subcategories are always displayed first before the products.

The alarm bell wrang after reading that line, it is not a requirement of the problem but just a viewing of the results. More than math looking at Design Patterns will help you.
The mathematical solution of this problem is completely wrong for Web Programming.
First separate your entities i.e. divid your problem to Categories, Products etc., 2nd solve the problem for each group separately, Last display the products and categories in a way that they are not coupled ( i.e. choosing one does not effect what you see in other one).
Lastly try asp.net, there were pre made samples that have already this scenario implemented. This is not a job for a web designer but a programmer. If this is a job for a client you will be way behind by the time it is gonna take to design, implement and test this approach, get a php shopping card close to what you need, then ponder about the math part separately.
