The core code of the PHP Lottery program (three lucky viewers)

Source: Internet
Author: User
  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); Get all participant information, everyone's information unique
  8. $award _users = Array ();//create a winning array
  9. if (count ($users) Else {
  10. $nums = Get_award3 ($users); Execute the Lottery and return the winner's subscript
  11. echo "award list is 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; Background audit draw list in storage (OK)
  22. Echo <<< EOF
  23. Lottery Information Warehousing

  24. EOF;

  25. function Get_award3 ($users) {//Lottery function, in order to prevent duplication, a more judgment
  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. ?>
Copy Code

We can refer to the implementation of the above code ideas, interested friends, self-implementation of a full PHP lottery program it.

  • Related Article

    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.