-
-
/** - * php lottery program core code
- * edit bbs.it-home.org
- */
- $sql = “select distinct(***),username from *** where daystatus=0 and ***= '{$yesterday}' and daystatus=0″ ;
- $res = mysql_query( $sql, $g_mysql ) or sys_exit( “The system is busy, please try again later”, mysql_error() ) ;
- $users = mysql_fetch_all( $ res ) ; //Get all participant information, each person's information is unique
- $award_users = array() ;//Create a winning array
- if ( count( $users ) else {
- $nums = get_award3( $users ) ; / /Execute the lottery program and return the subscript of the winner
- echo "The list of winners is as follows:" . ”
” ;
- foreach ( $nums as $key => $value ) {
- $ award_users[] = $users[$value] ;
- echo "uid:" . $users[$value]['uid'] . " Nickname: " . $users[$value]['username'] "
- " ;
- $uids[$key] = $users[$value]['uid'] ;
- }
- }
- $_SESSION['users'] = ” ;
- $_SESSION['users'] = $award_users ; //Backend Use
- echo <<Lottery information to enter the database
EOF;
- function get_award3( $users ) {//Lottery function, for To prevent duplication, there is an additional judgment
- $count = count( $users ) ;
- $i = 0 ;
- $result = array() ;
- while ( $i < 3 ) {
- $j = rand( 0, $count – 1 ) ;
- if ( ! in_array( $j, $result ) ) {
- $result[$i] = $j ;
- $i++ ;
- }
- }
- return $result ;
- }
- ?>
-
-
Copy the code
You can refer to the implementation ideas of the above code. Friends who are interested can implement a complete PHP lottery program by themselves.
|