jamieh Posted May 17, 2008 Share Posted May 17, 2008 Hey, I'm looking to create a little lottery script which will be usable on my website, basically it should run like this: *- User goes to the mainpage of the site, enters in 2 numbers between 1 - 20. *- these 2 numbers then get stored into a database with the rest of the numbers. *- Then when it's time for the lottery, i will press randomize in the admin section. *- This will then randomize numbers from 1 - 20 and output them on the mainpage. *- it then selects exactly the same numbers from the database that a user has inputted. *- Then it gives a list of winners and there numbers etc. So that's basically it, very small. I've found a few little scripts in google that randomizes numbers but haven't found any tutorials on how to select these numbers from the database or input them in anyway and then print them on the website. If there are any tutorials on this or anyone could help me, that would be great! Many thanks, Jamie Link to comment https://forums.phpfreaks.com/topic/106039-random-numbers/ Share on other sites More sharing options...
Barand Posted May 17, 2008 Share Posted May 17, 2008 As well as your user table (userID, user_name etc) id set up a table, userlotto, say, to store the users number (one record for each number) [pre] mysql> describe userlotto; +-------------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+---------------------+------+-----+---------+----------------+ | iduserlotto | int(10) unsigned | NO | PRI | NULL | auto_increment | | userID | int(10) unsigned | NO | | | | | drawno | int(10) unsigned | NO | | | | | entry | tinyint(3) unsigned | NO | | | | +-------------+---------------------+------+-----+---------+----------------+ Sample data mysql> SELECT * FROM userlotto; +-------------+--------+--------+-------+ | iduserlotto | userID | drawno | entry | +-------------+--------+--------+-------+ | 1 | 1 | 1 | 15 | | 2 | 1 | 1 | 18 | | 3 | 2 | 1 | 20 | | 4 | 2 | 1 | 2 | | 5 | 3 | 1 | 15 | | 6 | 3 | 1 | 6 | | 7 | 1 | 2 | 15 | | 8 | 1 | 2 | 18 | | 9 | 2 | 2 | 4 | | 10 | 2 | 2 | 14 | +-------------+--------+--------+-------+ 10 rows in set (0.00 sec)[/pre] If the winning numbers for draw 1 are 15, 18 mysql> SELECT userID, COUNT(*) as matches FROM userlotto WHERE entry IN (15,18) AND drawno = 1 GROUP BY userID HAVING matches=2; +--------+---------+ | userID | matches | +--------+---------+ | 1 | 2 | +--------+---------+ Link to comment https://forums.phpfreaks.com/topic/106039-random-numbers/#findComment-543464 Share on other sites More sharing options...
jamieh Posted May 17, 2008 Author Share Posted May 17, 2008 Thank you my friend, I'll try this and see how i get on. Many thanks, Jamie Link to comment https://forums.phpfreaks.com/topic/106039-random-numbers/#findComment-543471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.