A bit of background.
I run a fishing website, normally when we have a Match at a lake, we pull our peg numbers from a bag and thats the peg you fish for the day.
However, people are arriving at seperate times, so we are trying to do this online.
So in english this is what im trying to achieve.
On a lake there are say 32 pegs, so my array is (1,2,3,4,5.etc to.32) I want the user to complete a form, and the script to randomly select one of the above numbers, data returned is say "David" "Peg 5".
I need David and his peg (5) to be logged into a MySQL database and the number 5 to disapear from my array.
Any help to kick me off would be most appriciated. Im not fantastic with PHP but I know a bit, I just cant seem to get started!
Thanks in advance
Si
Random number, then remove from a list
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
the function array_rand, or shuffle will be of assistance here..
after a quick think, make a table for pegs with a second column for name of angler..
PegNum (Primary Key, Not Null), Name (Default=Null)
Then fill it with a row for each peg, and of course the peg number goes in PegNum, but leave Name blank.. as you don't know who has which peg yet.
The rest I shall leave to you, good luck 
after a quick think, make a table for pegs with a second column for name of angler..
PegNum (Primary Key, Not Null), Name (Default=Null)
Then fill it with a row for each peg, and of course the peg number goes in PegNum, but leave Name blank.. as you don't know who has which peg yet.
Code: Select all
<?php
$pegs = array();
$query = "SELECT `PegNum` FROM `Pegs` WHERE `Name` = NULL;";
$result = mysql_query($query) or die('of death');
while ($row = mysql_fetch_assoc($result)) {
$pegs[] = $row['PegNum'];
}
$randomPeg = $pegs[array_rand($pegs)]; //this is the random generated peg number..
?>- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Code: Select all
WHERE `Name` = NULL;Code: Select all
WHERE Name IS NULL