supanoob Posted May 12, 2006 Share Posted May 12, 2006 well, i want to be able to run 3 different things using the same script. the way i want it to work is using a drag down box where you select the thing you want to do. for example:i am making a gym, and i have Power, Speed and Dexterity now they all increase by the same random ammount. using the code below:[code]if ($fatigue < 2){echo "you do not have enough fatigue to do this";die();}$rand=rand(1,7);$rand=$rand/10;$update=$speed+$rand;$update2=$fatigue-2;$sql2="UPDATE players SET speed='$update', fatigue='$update2' WHERE user='$user'";if(mysql_query($sql2))[/code]right, thats the code i am using at the moment for Speed ONLY.now what i would like to do to save server space and loading time, is allow people to select what to train using a drop down menu, and it run that script for whatever they select. so if they select power it would run the script above but train power instead of speed. if someone could help me i would be grateful. Quote Link to comment https://forums.phpfreaks.com/topic/9563-multiple-things-on-1-script/ Share on other sites More sharing options...
Carth Posted May 12, 2006 Share Posted May 12, 2006 Pass it as a GET or POST var in the form, and then detect which one they are changing.For example on your HTML:[code]<select name="option" size="1"> <option value="0">Speed</option> <option value="1">Power</option> <option value="2">Dexterity</option></select>[/code]Then in PHP[code]switch($option) {case 0: // speed break;case 1: // power break;case 2: // dexterity break;default: echo "error"}[/code]If the code to calculate the new values is the same for them all, you can do that before the switch statement, and let the switch statement decide which part of the database to update. You could use the direct result of the drop down box (e.g. make the form return "speed" in the $option var) in the SQL statement, but you could be at risk of code injection if someone puts something malicious there. Quote Link to comment https://forums.phpfreaks.com/topic/9563-multiple-things-on-1-script/#findComment-35318 Share on other sites More sharing options...
supanoob Posted May 13, 2006 Author Share Posted May 13, 2006 i dont understand what you mean :S what do i need to change on the script, where it says speed do i need to put option or summin like that? Quote Link to comment https://forums.phpfreaks.com/topic/9563-multiple-things-on-1-script/#findComment-35446 Share on other sites More sharing options...
ignace Posted May 13, 2006 Share Posted May 13, 2006 DROPDOWN FORM[code]$form = '<select name="option" onChange="window.location.href=\'file.php?option=\'+this.options[this.selectedIndex].value;"><option value="0">Speed</option><option value="1">Power</option><option value="2">Dexterity</option></select>';[/code]BACK TO YOUR PHP[code]$option = trim( strip_tags( $_REQUEST['option'] ));switch( $option ){ case 0: .... if( $fatique < 2 ){ print( 'you do not have enough fatique to do this.' );//leave the die(); command out or use die( 'you do not..' ); } .... break; case 1: ... power it up ... break; case 2: ... dextergy WRAAAAWWWW ... break; default: print( $form ); break;}$rand=rand(1,7);$rand=$rand/10;$update=$speed+$rand;$update2=$fatigue-2;$sql2="UPDATE players SET speed='$update', fatigue='$update2' WHERE user='$user'";if(mysql_query($sql2))[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9563-multiple-things-on-1-script/#findComment-35522 Share on other sites More sharing options...
supanoob Posted May 13, 2006 Author Share Posted May 13, 2006 ummm, ok so most of that makes sense except the part at the end where you have left it to update in the Speed column still :s shouldnt that be where "Option" (take away the "") =$user? Quote Link to comment https://forums.phpfreaks.com/topic/9563-multiple-things-on-1-script/#findComment-35559 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.