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
https://forums.phpfreaks.com/topic/79783-solved-number-counter/
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
https://forums.phpfreaks.com/topic/79783-solved-number-counter/#findComment-404082
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.