Core code of the php lucky draw program (selecting three lucky viewers)
/**
- * 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); // obtain information about all participants. The information of each participant is unique.
- $ Award_users = array (); // creates a winning array
- If (count ($ users) else {
- $ Nums = get_award3 ($ users); // executes the lucky draw program and returns the subscript of the winner.
- Echo "the winners are listed 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; // used when the lottery drawing list is checked in the background (confirmed)
- Echo <EOF
- Lottery information warehouse receiving
EOF;
- Function get_award3 ($ users) {// lottery function. multiple judgments are provided to prevent repetition.
- $ 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;
- }
- ?>
-
You can refer to the implementation ideas of the above code. if you are interested, you can implement a complete php lucky draw program by yourself. |