• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Challenge] 3 Conditions + Random + Paginate

#1
[eluser]Unknown[/eluser]
I have a tricky issue to solve, let me see if you can help me...

Im developing a services directory using CodeIgniter + MySQL and, due to my client's business rules, theres 3 plan types. (Platinum, Gold and Silver - in this order from best to worse)

There is a table with the companies tha advertise in the directory, and each one of them may be paying one of this 3 plans.

The problem is:

I have to present the results following this rules:
1. Platinum comes first, than gold, than silver
2. Each range of results MUST BE random itself

Code:
Platinum 2
Platinum 1
Platinum 3
Gold 3
Gold 1
GOld 2
Silver 2
Silver 3
Silver 1

refresh and i get:

Code:
Platinum 1
Platinum 3
Platinum 2
Gold 2
Gold 1
GOld 3
Silver 2
Silver 1
Silver 3

Until now, so far so good. The problem is, with so many results, i have to paginate them Smile How can i do this keeping in mind that:
- The plan priority must be the same through the pages
- the results must be random within the plan "blocks"
- BUT the pagination CANT repeat records through pages or omiss some results

i have to achieve something like this (e.g. with a 4 per page pagination)

Code:
Page I:
Platinum 1
Platinum 4
Platinum 5
Platinum 3

Page II:
Platinum 2
Gold 5
Gold 3
Gold 1

Page III:
Gold 4
Gold 2
Silver 2
Silver 5

Page IV:
Silver 1
Silver 3
Silver 4

and refreshing, randomly changing the position of records INSIDE THE PLAN BLOCKS, within the pages, without repeat or omiss results in the 4 pages, in this example.

Somebody can help me, please. Its a challenge one Wink Thanks, Adriano.

#2
[eluser]CroNiX[/eluser]
Just use normal pagination and then when it comes to displaying the results just use shuffle() on your results array before looping and displaying data in your view. That will keep your pagination in tact, not repeat any results, and randomize each page (or block, depending on where you do this)

#3
[eluser]Unknown[/eluser]
the thing is. I have to randomize the results in page WITHOUT mess with global plans priority.
if in page 2 after randomize, platinum results and gold results coexist, platinum MUST show first in page


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.