Jump to content

Recommended Posts

Hello i'm trying to build a script that would do something like this:

the user is allowed to submit 20 numbers

ex: 3,7,20,25,64....

after all users submited their numbers

computer will generate using rand() 12 numbers from 1 to 80(same as the user has the option to choose from 1 to 80).

after this two points i must check if one or more of the computers generated numbers is = to 1 or more numbers submited by a user.

i'm not asking for you to provide a code or something like this...

my question is how can i do this using php and mysql... examples are welcome.. :)

So am i correct in saying you want, the user to enter 20 number(range 1-80),

and then th server, to generates 2 random number (also range 1-80) and then check to see if its 2 are in the list of 20 the user submitted ?

 

one question.. where does the mysql come into play ?

 

Heres a quick untested example

 

<?php
$user_array = explode(",", $_POST['uservalues']); //ie <input name="uservalues" type="text" value="1,2,3">

//build array of 2 unique numbers
$sysarray = array();
while(count($sysarray)<2)
{
$sysarray[] = rand(1, 80);
$sysarray = array_unique($sysarray);
}

if(in_array($sysarray[1], $user_array) && in_array($sysarray[1], $user_array) )
{
//both found
echo ""woohoo;
}

?>

 

So am i correct in saying you want, the user to enter 20 number(range 1-80),

and then th server, to generates 2 random number (also range 1-80) and then check to see if its 2 are in the list of 20 the user submitted ?

 

one question.. where does the mysql come into play ?

 

 

So am i correct in saying you want, the user to enter 20 number(range 1-80),

and then th server, to generates 2 random number (also range 1-80) and then check to see if its 2 are in the list of 20 the user submitted ?

 

one question.. where does the mysql come into play ?

 

 

mm it's not only for one user it's for more.. let's say about 100 - 200 users submit this 20 numbers.. and computer generates 12 numbers .. and that has to check if one or more of those 12 numbers are identic with one or more numbers submited by a users

 

 

 

 

 

Do you know about if statements?

 

yes i know about if statements..

My apologies, I didn't really understand what you were asking, as you didn't explain yourself very well.

 

You could use MadTechie's code, but stick it in a while loop for each person's numbers in the database. Then generate an array of people whose numbers match.

Sounds like a lotto script, with outrageous odd.

Thats where I would look for some inspiration.

U can store the numbers into mysql, but the table will get out of hand quickly, (because its small amount of info stored in huge amounts). So you may want to clear this table often (Like every new game).

 

so u need user authentication (allow ppl to login), and the user chosen numbers table, and a MySQL that GROUPs the numbers against computer drawn numbers.

I was playing with sqlite and did come up with a simple table structure, and a query that appears to work.

 

I built my tables like

CREATE TABLE [ticketnumbers] (
[id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
[tid] INTEGER  NOT NULL,
[number] TINYINT  NOT NULL
);

CREATE TABLE [tickets] (
[id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[uid] INTEGER  NOT NULL,
[purchased] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL
);

CREATE TABLE [users] (
[id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[name] VARCHAR(30)  UNIQUE NOT NULL,
[password] VARCHAR(16)  NOT NULL,
[email] VARCHAR(64)  UNIQUE NOT NULL,
[added] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
[laston] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);

 

well I got a little out of hand on users table, but just needed some visuals.

than I created some test data, 100 users, 200 tickets purchases, and 1600 numbers

(this was pure random data, so didnt make every ticket hold 12 numbers)

 

a quick check with SQL, to verify tickets and numbers

SELECT * FROM ticketnumbers WHERE number IN(12,31,68) order BY tid

 

but ya see how complex it gets?

so I made another query that kinda gave me more useful info

SELECT tid,count(number) as matches,group_concat(number) as numbers FROM ticketnumbers WHERE number IN(12,31,68) GROUP BY tid ORDER BY matches DESC

 

Hmmm, not bad :)

the query seemed to work, but this was all done with just the db, random generated test date

and a lil searching on the net (I learned that group_concat isnt supported in SQLite until version 3.5.4))

 

I was playing with sqlite and did come up with a simple table structure, and a query that appears to work.

 

I built my tables like

CREATE TABLE [ticketnumbers] (
[id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
[tid] INTEGER  NOT NULL,
[number] TINYINT  NOT NULL
);

CREATE TABLE [tickets] (
[id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[uid] INTEGER  NOT NULL,
[purchased] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL
);

CREATE TABLE [users] (
[id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[name] VARCHAR(30)  UNIQUE NOT NULL,
[password] VARCHAR(16)  NOT NULL,
[email] VARCHAR(64)  UNIQUE NOT NULL,
[added] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
[laston] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);

 

well I got a little out of hand on users table, but just needed some visuals.

than I created some test data, 100 users, 200 tickets purchases, and 1600 numbers

(this was pure random data, so didnt make every ticket hold 12 numbers)

 

a quick check with SQL, to verify tickets and numbers

SELECT * FROM ticketnumbers WHERE number IN(12,31,68) order BY tid

 

but ya see how complex it gets?

so I made another query that kinda gave me more useful info

SELECT tid,count(number) as matches,group_concat(number) as numbers FROM ticketnumbers WHERE number IN(12,31,68) GROUP BY tid ORDER BY matches DESC

 

Hmmm, not bad :)

the query seemed to work, but this was all done with just the db, random generated test date

and a lil searching on the net (I learned that group_concat isnt supported in SQLite until version 3.5.4))

 

 

thank you very much for you example and for all those who posted here.. you've been really helping i've solved the problems and already started to coding.. diagram for mysql is finish and the diagram for the website backend + user :)

i will hit topic solved but if anyone is interested to continue this topic.. :) and come with ideeas i think everyone will be glad to hear them.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.