Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 521841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:17:31+00:00 2026-05-13T08:17:31+00:00

I have created a lottery script in php. My problem is now selecting more

  • 0

I have created a lottery script in php. My problem is now selecting more then one winner. Because it is possible for players to have the same number on their tickets. Here I am supplying the two table structures and the source code.

lotto_game {
    id(int)
    jackpot(int)
    status(varchar10)
    pick_1(int)
    pick_2(int)
    pick_3(int)
    pick_4(int)
    pick_5(int)
    tickets_sold(int)
    winner(text)
}

 lotto_picks {
    lotto_id(int)
    user_id(int)
    choice_1(int)
    choice_2(int)
    choice_3(int)
    choice_4(int)
    choice_5(int)
    ticket_status(int)
}

These are my two tables with in my database. For examples sake we will create 2 users with the id’s 1, and 2. So what happens is when the script runs it is suppose to change the lotto_game status from ‘active’ to ‘finished’ then add the random lottery numbers into each pick_* column.

$one = rand(1,30);
$two = rand(1,30); 
$three = rand(1,30);
$four = rand(1,30);
$five = rand(1,30);

mysql_query("UPDATE `lotto_game` SET 
 pick_1 = '$one',
 pick_2 = '$two',
 pick_3 = '$three',
 pick_4 = '$four',
 pick_5 = '$five',
 status = 'finished' 

WHERE status = ‘active'”);

That wasn’t too hard I will admit. But this is just the beginning of the end.

$lotto['tickets'] = mysql_query("SELECT ticket_id FROM `lotto_picks` WHERE ticket_status='valid'");

@$lotto[winners] = mysql_query("SELECT ticket_id,user_id FROM `lotto_picks` WHERE choice_1 = '$one' AND choice_2 = '$two' AND choice_3 = '$three' AND choice_4 = '$four' AND choice_5 = '$five'");

$lotto['num_tickets'] = mysql_num_rows($lotto['tickets']);
@$lotto[winner_id] = mysql_fetch_array(@$lotto[winners]);
$lotto['jackpot'] = mysql_query("SELECT jackpot FROM `lotto_game` WHERE status='active'");

$lotto['winner_jackpot'] = mysql_fetch_array($lotto['jackpot']);
$lotto['num_winners'] = mysql_num_rows($lotto['winners']);
//echo @$lotto['num_tickets'];
//echo @$lotto['num_winners'];
$winner = $lotto['num_winners'];
//echo @$lotto['winner_id']['user_id'];
$jackpot = $lotto['winner_jackpot']['jackpot'];
$id = @$lotto[winner_id][user_id];
if ($winner == 1) {
    mysql_query("UPDATE `character` SET
    decivers = decivers +'$jackpot'
WHERE user_id='$id'");
}

This is what I have come up with and it really seems to work with one winner. But I just cant figure out where to go from here. I have tried using some arrays but nothing works. I know what needs to be done but can’t figure out how to do it.

When I search for winners I need to put into an array all their user id’s.

so extra decivers is money, if anyone is confused on that. The status on the tickets doesn’t really matter here but if you must know it just determines if the ticket_status is ‘valid’ or ‘invalid’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:17:32+00:00Added an answer on May 13, 2026 at 8:17 am
    $winners_array = array();
    if(mysql_num_rows($lotto['winners'])!=0){
      while($row =mysql_fetch_array($lotto['winners'])){
        if(!in_array($row['user_id'],$winners)) $winners[] = $row['user_id'];
      }
    }
    

    $winners will be an array with all the winners user_ids

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer An EnumSet is also a collection, so you can use… May 16, 2026 at 5:20 pm
  • Editorial Team
    Editorial Team added an answer There are two differences between 'use' and 'require'. One of… May 16, 2026 at 5:20 pm
  • Editorial Team
    Editorial Team added an answer The problem is that the selector ul.parent li a in… May 16, 2026 at 5:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have created a PHP-script to update a web server that is live inside
I have the following table containing the winning numbers of 6/49 lottery. +-----+------------+----+----+----+----+----+----+-------+ |
Have created a c++ implementation of the Hough transform for detecting lines in images.
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created a template for Visual Studio 2008 and it currently shows up
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a UserControl that has a ListView in it. The ListView is
I have created a C# class file by using a XSD-file as an input.
I have created alot of stored procedures in my application that return the result
I have created a sample application suing Application cache, My some files are located

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.