Jump to content

[SOLVED] Number counter?


czukoman20

Recommended Posts

I have an issue with what i am trying to do for my site. I am not sure where to start to do this. The setup i have already is i have an ID number to every user. The ID number is then used to get all of the info that i want to see on that user.

I would like to be able to display this information on 1 page with 5 per page.

The only issue is. Say i have 400 users on my site all that want to display information.

I would like it so nobody gets a better deal over someone else. So i figured it should be randomized. so 5 out of 400 users per page.

But then i thought.. well now i dont want the same user popping up more than once before the whole entire 400 users have been looked at.

Is there any possible way to display 5 users randomly per page, but not have any random user repeats.

 

Thanks .. if this isnt clear please tell me so i can make a diagram.  ;)

 

Link to comment
Share on other sites

try

<?php
session_start();
$IDs = range(1,10);// your ID array
$randID = array();
$per_page = 3;
if (isset($_SESSION['rID'])) $randID = $_SESSION['rID'];
if (count($randID) < $per_page){
shuffle($IDs);
$randID = array_merge($randID,$IDs);
$randID = array_values(array_unique($randID));
}
$curIDs = array(); 
for ($i = 0; $i < $per_page; $i++){ 
$curIDs[] = $randID[$i];
unset($randID[$i]);
}
$_SESSION['rID'] = array_values($randID);

foreach ($curIDs as $v) echo $v, "<br />\n";
?>
<a href="">Next</a>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.