PHDDriver Posted May 19, 2013 Share Posted May 19, 2013 Hi, I was wanting to make a simple script that would assign entry numbers to every input box, then randomly generate a number, and eliminate the input box if its assigned entry number was generated. Until only 1 assigned number was left, ending the game. I don't know which is best way to do this.. jquery, js, php, or something else. php seems easiest to learn so i started with it but will change if there is easier way. am having trouble on "page2.php" part. I don't know how to carry over data from page1 to page2 I'll try an explain in this step-by-step process of what im trying to do... Say on page1.php, a person would select the number of input boxes they wanted to use, then fill in a name for each input box.Like this: *Clicks drop-down menu showing numbers 2-100, selects "5", then 5 input boxes appear* 1. Mike 2. Joe 3. Ken 4. Barbie 5. John Then click "Submit" taking them to page2.php where the script randomly eliminated the input boxes 1 number at a time until only 1 number was left Like This: Game #1 is starting... 5 - John 2 - Joe 1 - Mike 4 - Barbie Results ---------- 1st Place: Ken 2nd Place: Barbie 3rd Place: Mike Quote Link to comment https://forums.phpfreaks.com/topic/278187-a-simple-elimination-game/ Share on other sites More sharing options...
Jessica Posted May 19, 2013 Share Posted May 19, 2013 (edited) You should use the Session to store data. Edited May 19, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/278187-a-simple-elimination-game/#findComment-1431080 Share on other sites More sharing options...
PHDDriver Posted May 19, 2013 Author Share Posted May 19, 2013 thanks, will give that a try right now =) thanks a bunch for the quick reply much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/278187-a-simple-elimination-game/#findComment-1431082 Share on other sites More sharing options...
ignace Posted May 20, 2013 Share Posted May 20, 2013 (edited) You need JavaScript to generate the input boxes, though jQuery will be simpler to use. // credits: http://stackoverflow.com/a/10142256 Array.prototype.shuffle = function() { var i = this.length, j, temp; if ( i == 0 ) return this; while ( --i ) { j = Math.floor( Math.random() * ( i + 1 ) ); temp = this[i]; this[i] = this[j]; this[j] = temp; } return this; } var playerNames = ['Mike', 'Joe', 'Ken', 'Barbie', 'John'], // add up to 100 names here totalPlayers = 5, // number selected by the user htmlStr = '', tpl = '<div><label for="{id}">{label}</label><input type="text" id="{id}" name="names[]" value="{name}"></div>'; playerNames.shuffle().slice(0, totalPlayers).forEach(function(name, i) { htmlStr += tpl.replace(/\{id\}/g, 'player' + i) .replace(/\{label\}/g, 'Player #' + i) .replace(/\{name\}/g, name); }); $(htmlStr).appendTo('#playersForm');When you submit the form you will be able to access the names in PHP as: $names = $_GET['names']; print_r($names); Edited May 20, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/278187-a-simple-elimination-game/#findComment-1431128 Share on other sites More sharing options...
PHDDriver Posted May 20, 2013 Author Share Posted May 20, 2013 I've been reading php tutorials all day, and none of this is making much sense to me, i thought maybe it would, guess I was wrong. I am just stick with mIRC. thanks again for all the help, sorry to have wasted your time. you've been very helpful ignace, thank you Quote Link to comment https://forums.phpfreaks.com/topic/278187-a-simple-elimination-game/#findComment-1431264 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.