Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

This a question for al the geniuses in math, Looking for a math formula to get a value

0 views
Skip to first unread message

SM

unread,
Oct 9, 2008, 12:56:17 AM10/9/08
to
This a question for the math genius...

i have an 3 dimensional array representing CD's...
I want to do pagination without getting the value of the current page
in the url (linking issues). So i want to use a mathematical formula
to get the current page...

Here's where i am right now:
--------------------------------
$cat = $_GET['cat'];

$cds = array(
1=> array(
ClOHCQiD=> array('xxx', 'yyy'),
pZrhrRRX=> array('xxx', 'yyy'),
Lk3AGW6P=> array('xxx', 'yyy'),
XXXXXXXX=> array('xxx', 'yyy'),
t1knTITi=> array('xxx', 'yyy'),
yJd6OBlM=> array('xxx', 'yyy'),
J1tiIzSE=> array('xxx', 'yyy'),
22222222=> array('xxx', 'yyy')
),

2=> array(
ClOHCQiD=> array('xxx', 'yyy'),
pZrhrRRX=> array('xxx', 'yyy'),
Lk3AGW6P=> array('xxx', 'yyy'),
GIeWMFBa=> array('xxx', 'yyy')
)
);

//pagination
$p_perpage = 3;
$p_totalcds = count($cds[$cat]); //total = 8
$p_totalpages = ceil($p_totalcds / $p_perpage);

????
$p_thispage = ????; //get this value depending on the position of the
$cd in array

-----------------------

Let's just pretend that $cat = 1. If the key string of the array $cds
is 'XXXXXXXX' that would mean that the value $p_thispage = 2. I've
arrived at that conclusion by considering the key position of the
value 'xxxxxxxx' in the array $cds[1] and also that the per page value
= 3...

If the key string in $cds is '22222222' then $p_thispage = 3 and so
on...

Usin the above example and If I had this:
$p_perpage = 5;
$p_totalcds = count($cds[$cat]);
$p_totalpages = ceil($p_totalcds / $p_perpage);

then
$p_thispage = 1


Knowning that these variables (per page.. total of cds...) could
change in the future, what could be a good mathematical formula to get
the value for the variable $p_thispage. My brain is almost bleeding
with all the searching and trying with no success... you could call it
an effor to nowhere...

Thanks again
Marco

Jerry Stuckle

unread,
Oct 9, 2008, 2:13:05 PM10/9/08
to

Why not just store the current page in a hidden field and POST the form
back for your next/prev buttons?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

SM

unread,
Oct 9, 2008, 4:50:21 PM10/9/08
to
> jstuck...@attglobal.net
> ==================

that could also be a solution... thanks for the idea...
i'm gonna ask the same question in a math forum group... if they came
up with something i'll posted here for everybody to see...

SM

unread,
Oct 9, 2008, 6:10:38 PM10/9/08
to


I've posted the following question in a math group. I'll keep you
posted:

I need to find a mathematical formula for this next problem...

I have a list containing 13 items. The list is dynamic, wich means
that sometimes it could contains 20 items or 35 items o only 4 items.

I want to show the items in groups of 4. Again, this is dynamic.
Sometimes i want to show the items in groups of 11, 2, etc...

So, if i have 34 items and i want to show it in groups of 10, I would
end up having 4 groups (3 groups of 10, and 1 group of 4)... So far so
good. Let's continue. If item 'joe' is the 12th item, then item 'joe'
is in group 2. right? If the item 'banana' is the 8th item, then item
'banana' is in group 1...and so on...

This is were it gets complicated for me. I need to find the group were
the item resides

So, let's recap. Knowing the total of items and the number of items
per group (also, with those two variables you can guess the total of
groups), and knowing the position of the item in the list, how do i
found out in wich group the item resides?

I'm looking for some sort of a miracle mathematical formula so i can
incorporate it in a program i'm building. Does a formula exist???

Thanks in advance
Marco
---

Michael Fesser

unread,
Oct 9, 2008, 6:37:26 PM10/9/08
to
.oO(SM)

>I've posted the following question in a math group. I'll keep you
>posted:
>
>I need to find a mathematical formula for this next problem...
>
>I have a list containing 13 items. The list is dynamic, wich means
>that sometimes it could contains 20 items or 35 items o only 4 items.
>
>I want to show the items in groups of 4. Again, this is dynamic.
>Sometimes i want to show the items in groups of 11, 2, etc...
>
>So, if i have 34 items and i want to show it in groups of 10, I would
>end up having 4 groups (3 groups of 10, and 1 group of 4)... So far so
>good. Let's continue. If item 'joe' is the 12th item, then item 'joe'
>is in group 2. right? If the item 'banana' is the 8th item, then item
>'banana' is in group 1...and so on...

<?php
$itemsPerGroup = 10;
$itemPosition = 12;
$group = ceil($itemPosition/$itemsPerGroup);
var_dump($group);
?>

Micha

SM

unread,
Oct 9, 2008, 11:47:19 PM10/9/08
to

Thanks, just what i need it.

0 new messages