Core code of the php lucky draw program (selecting three lucky viewers)

Source: Internet
Author: User
Core code of the php lucky draw program (selecting three lucky viewers)

  1. /**

  2. * Php lottery program core code
  3. * Edit bbs.it-home.org
  4. */
  5. $ SQL = "select distinct (***), username from *** where daystatus = 0 and *** = '{$ yesterday}' and daystatus = 0 ″;
  6. $ Res = mysql_query ($ SQL, $ g_mysql) or sys_exit ("The system is busy. please try again later", mysql_error ());
  7. $ Users = mysql_fetch_all ($ res); // obtain information about all participants. The information of each participant is unique.
  8. $ Award_users = array (); // creates a winning array
  9. If (count ($ users) else {
  10. $ Nums = get_award3 ($ users); // executes the lucky draw program and returns the subscript of the winner.
  11. Echo "the winners are listed as follows :"."

  12. ";

  13. Foreach ($ nums as $ key => $ value ){
  14. $ Award_users [] = $ users [$ value];
  15. Echo "uid:". $ users [$ value] ['uid']. "nickname:". $ users [$ value] ['username']"
  16. ";
  17. $ Uids [$ key] = $ users [$ value] ['uid'];
  18. }
  19. }
  20. $ _ SESSION ['users'] = ";
  21. $ _ SESSION ['users'] = $ award_users; // used when the lottery drawing list is checked in the background (confirmed)
  22. Echo <EOF
  23. Lottery information warehouse receiving

  24. EOF;

  25. Function get_award3 ($ users) {// lottery function. multiple judgments are provided to prevent repetition.
  26. $ Count = count ($ users );
  27. $ I = 0;
  28. $ Result = array ();
  29. While ($ I <3 ){
  30. $ J = rand (0, $ count-1 );
  31. If (! In_array ($ j, $ result )){
  32. $ Result [$ I] = $ j;
  33. $ I ++;
  34. }
  35. }
  36. Return $ result;
  37. }
  38. ?>

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.