czukoman20 Posted December 8, 2007 Share Posted December 8, 2007 Ok i have a question How would i implement this code that i wrote to use a rand id function. The setup i would like to create is. Randomly put 10 userid's in a lineup. pick the first random 5, and i display those five on a page, then when the user hits next page, it will exclude the five that it showed already, and display the last five. Here is what i have written for the displaying part. This setup below searches for the user with a userid of 1, then displays information on them <?mysql_select_db('db215169417') or die('Error, cannot select mysql database'); $userid_1 = 1; $query = mysql_query("SELECT * FROM users WHERE userid_2='$userid_1'"); $values = mysql_fetch_array($query); $nrRows = mysql_num_rows($query); if($nrRows == 1){ $username = $values['username']; echo " <img src=\"http://www.adworld-online.com/images/banners/$username"."_banner.jpg\"> <br>"; echo ".::. Company: " . $values['companyname'] . "<br> "; echo "Short info: " . $values['info'] . "<br> "; echo "<a href=\"http://www.adworld-online.com/submit.php?user=$username\">.::. Contact Us </a> <br />"; } else{ echo "There is no user with that id"; } ?> I have been experimenting with different random types like <?php session_start(); $IDs = range(1,10);// your ID array $randID = array(5,7); $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"; ?> This code was given to me from sasa That picks 3 numbers randomly and displays them, but it will display the same number twice if it is randomly picked output looks like this 6 10 8 ?> <?php $numbers = range(1, 10); srand((float)microtime() * 1000000); shuffle($numbers); foreach ($numbers as $number) { echo "$number "; } This one is the beginning part of what i was going for. It picks 10 numbers in order, and the output looks like this 7 2 8 3 4 10 9 6 1 5 I would greatly appreciate people to help me out on this one, because I'm not fluent with php just yet, and I would like some help please And please just keep the snottyness to a minimum thanks. Quote Link to comment Share on other sites More sharing options...
czukoman20 Posted December 9, 2007 Author Share Posted December 9, 2007 Do u guys understand what im saying, or is it just a big thing to think about? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.