Hello! I have set up a script form called " form tools " without a problem, This script gathers all information in the registration form and stores it into a database (php and mysql), Now I would like to randomly choose 5 people from the data I collected from the database randomly, Since it’s a game, I would like it to be as random as possible, how do I do this?
patmagpantay
0
Newbie Poster
Recommended Answers
Jump to PostIf you have a counter or id field in your table which is unique, you can do this easily.
<?php $connection=mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname); $query="select * from tablename"; $result=mysql_query($query); $max=mysql_num_rows($result);//count the total records in the table $random_members=array(); while(count($random_members) <= 5){ // until 5 members are selected $random=rand(1,$max);//generate random number …
All 3 Replies
nav33n
472
Purple hazed!
Team Colleague
Featured Poster
MickRip
0
Newbie Poster
nav33n
472
Purple hazed!
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.