Xyphon Posted December 23, 2007 Share Posted December 23, 2007 <?PHP include('Connect.php'); include('top.php'); $ID= $_COOKIE['UserID']; //If User Is Not Logged In if(!isset($ID)) { //Display Message echo "Sorry, you are not logged in.<br /><br /><a href='login.php'>Login</a>"; //Include Bottom File include("bottom.php"); //Exit Page exit; } $Action= $_GET['action']; $Result1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID'"); $Rows1= mysql_fetch_array($Result1); $PokemonRand= rand(1, 99); if($PokemonRand < 75 && $PokemonRand > 50) { $pokemonname="Magby"; $sorrymessage="<img border='0' src='http://i10.tinypic.com/8also6f.png'><br />Pokemon found! Want to catch?<form action='map1find.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(12,27); $defence= rand(15,23); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonicon="http://i9.tinypic.com/6owv9l0.png"; $pokemonimage="http://i10.tinypic.com/8also6f.png"; } elseif($PokemonRand < 100 && $PokemonRand > 74 ) { $pokemonname="Charmander"; $sorrymessage="<img border='0' src='http://i13.tinypic.com/6xvsvw7.png'><br />Pokemon found! Want to catch?<form action='map1find.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(15,23); $defence= rand(12,27); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonicon="http://i13.tinypic.com/6l2w8l2.png"; $pokemonimage="http://i13.tinypic.com/6xvsvw7.png"; } elseif($PokemonRand < 51 && $PokemonRand > 49 ) { $pokemonname="Entei"; $sorrymessage="<img border='0' src='http://i8.tinypic.com/7xxnyud.png'><br />Pokemon found! Want to catch?<form action='map1find.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(20,37); $defence= rand(23,34); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonimage="http://i8.tinypic.com/7xxnyud.png"; $pokemonicon="http://i2.tinypic.com/6wp5cmq.png"; } else { $sorrymessage="Nothing found. Keep looking."; } $pokemonrand2= rand(1, 99); //If Gender Is Male if($pokemonrand2 < 50 && $pokemonrand2 > 0) { //Define Promo Variables $pokemongender="Male"; } //If Gender Is Female elseif($pokemonrand2 < 99 && $pokemonrand2 > 50) { //Define Promo Variables $pokemongender="Female"; } //If Promo Is Ungendered else { //Define Promo Variables $pokemongender="Ungendered"; } //If User Has No Pokémon if(empty($Rows1)) { //Display Message echo "Sorry, you must obtain your starter first.<br /><br /><a href='obtainstarter.php'>Obtain Starter</a>"; //Include Bottom File include("bottom.php"); //Exit Page exit; } //Find Position Results $AP_PResult1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='1'"); $AP_PResult2= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='2'"); $AP_PResult3= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='3'"); $AP_PResult4= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='4'"); $AP_PResult5= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='5'"); $AP_PResult6= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='6'"); //Find Position Rows $AP_PRows1= mysql_fetch_array($AP_PResult1); $AP_PRows2= mysql_fetch_array($AP_PResult2); $AP_PRows3= mysql_fetch_array($AP_PResult3); $AP_PRows4= mysql_fetch_array($AP_PResult4); $AP_PRows5= mysql_fetch_array($AP_PResult5); $AP_PRows6= mysql_fetch_array($AP_PResult6); //Set Position Variable $AP_MainPosition="No"; //Find Position One if(empty($AP_PRows1)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 1; $AP_MainPosition="Yes"; } } //Find Position Two elseif(empty($AP_PRows2)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 2; $AP_MainPosition="Yes"; } } //Find Position Three elseif(empty($AP_PRows3)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 3; $AP_MainPosition="Yes"; } } //Find Position Four elseif(empty($AP_PRows4)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 4; $AP_MainPosition="Yes"; } } //Find Position Five elseif(empty($AP_PRows5)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 5; $AP_MainPosition="Yes"; } } //Find Position Six elseif(empty($AP_PRows6)) { //If Main Position Is No if($AP_MainPosition=="No"); { //Define Variables $AP_Slot= 6; $AP_MainPosition="Yes"; } } //Find Box Position else { //Define Variables $AP_Slot= 7; $AP_MainPosition="Yes"; } if(!isset($Action)) { echo "$sorrymessage<br />"; echo "Click on the map to find pokemon!<br />"; echo "<a href='map1find.php'><img border='0' src='http://i13.tinypic.com/8104aqe.jpg'></a>"; } else { echo "You caught the Pokemon!<br />"; echo "Click on the map to find pokemon!<br />"; echo "<a href='map1find.php'><img border='0' src='http://i13.tinypic.com/8104aqe.jpg'></a>"; mysql_query("INSERT INTO pokemon_info (user_id, pokemon_name, pokemon_attack, pokemon_defence, pokemon_image, pokemon_gender, pokemon_icon, pokemon_level, pokemon_exp, pokemon_nexp, attack1, attack2, attack3, attack4, pokemon_slot) VALUES ('$ID', '$pokemonname', '$attack', '$defence', '$pokemonimage', '$pokemongender', '$pokemonicon', '$level', '$EXP', '$NEXP', '$attack1', '$attack2', '$attack3', '$attack4', '$AP_Slot')")or die(mysql_error()); } include('bottom.php'); ?> Well, the problem is, it rands twice. Meaning they'll go to catch Charmander, and might get Magby. Can you help? Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/ Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 Far to much code to look through. Can't you be more specific? Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421410 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 Well. I mean, at th top when its defining what pokemon is shown, I put a rand there, and at the bottom, when It shows caught, it rands again, so after they catch it it rands again and they get a differant pokemon. Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421413 Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 I'm failing to understand what the problem is. You say a random number is generated twice from one rand()? Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421414 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 No. Its generated ONCE! Then AFTER I click submit, it is randed again in the you got pokemon part. Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421417 Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 Calm down, your description isnt exactly amazing. Use sessions. session_start(); $_SESSION['rand'] = $PokemonRand; That should help. Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421419 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 I have no experience with sessions. Where do I use that and how do I use it in my script to fix my problem? Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421420 Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 I'm nice so here: <?PHP session_start(); include('Connect.php'); include('top.php'); $ID= $_COOKIE['UserID']; //If User Is Not Logged In if(!isset($ID)) { //Display Message echo "Sorry, you are not logged in.<br /><br /><a href='login.php'>Login</a>"; //Include Bottom File include("bottom.php"); //Exit Page exit; } $Action= $_GET['action']; $Result1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID'"); $Rows1= mysql_fetch_array($Result1); $PokemonRand= rand(1, 99); $_SESSION['rand'] = $PokemonRand; if($PokemonRand < 75 && $PokemonRand > 50) { $pokemonname="Magby"; $sorrymessage="<img border='0' src='http://i10.tinypic.com/8also6f.png'><br />Pokemon found! Want to catch?<form action='map1find.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(12,27); $defence= rand(15,23); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonicon="http://i9.tinypic.com/6owv9l0.png"; $pokemonimage="http://i10.tinypic.com/8also6f.png"; } elseif($PokemonRand < 100 && $PokemonRand > 74 ) { $pokemonname="Charmander"; $sorrymessage="<img border='0' src='http://i13.tinypic.com/6xvsvw7.png'><br />Pokemon found! Want to catch?<form action='map1find.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(15,23); $defence= rand(12,27); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonicon="http://i13.tinypic.com/6l2w8l2.png"; $pokemonimage="http://i13.tinypic.com/6xvsvw7.png"; } elseif($PokemonRand < 51 && $PokemonRand > 49 ) { $pokemonname="Entei"; $sorrymessage="<img border='0' src='http://i8.tinypic.com/7xxnyud.png'><br />Pokemon found! Want to catch?<form action='map1find.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(20,37); $defence= rand(23,34); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonimage="http://i8.tinypic.com/7xxnyud.png"; $pokemonicon="http://i2.tinypic.com/6wp5cmq.png"; } else { $sorrymessage="Nothing found. Keep looking."; } $pokemonrand2= $_SESSION['rand']; //If Gender Is Male if($pokemonrand2 < 50 && $pokemonrand2 > 0) { //Define Promo Variables $pokemongender="Male"; } //If Gender Is Female elseif($pokemonrand2 < 99 && $pokemonrand2 > 50) { //Define Promo Variables $pokemongender="Female"; } //If Promo Is Ungendered else { //Define Promo Variables $pokemongender="Ungendered"; } //If User Has No Pokémon if(empty($Rows1)) { //Display Message echo "Sorry, you must obtain your starter first.<br /><br /><a href='obtainstarter.php'>Obtain Starter</a>"; //Include Bottom File include("bottom.php"); //Exit Page exit; } //Find Position Results $AP_PResult1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='1'"); $AP_PResult2= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='2'"); $AP_PResult3= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='3'"); $AP_PResult4= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='4'"); $AP_PResult5= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='5'"); $AP_PResult6= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='6'"); //Find Position Rows $AP_PRows1= mysql_fetch_array($AP_PResult1); $AP_PRows2= mysql_fetch_array($AP_PResult2); $AP_PRows3= mysql_fetch_array($AP_PResult3); $AP_PRows4= mysql_fetch_array($AP_PResult4); $AP_PRows5= mysql_fetch_array($AP_PResult5); $AP_PRows6= mysql_fetch_array($AP_PResult6); //Set Position Variable $AP_MainPosition="No"; //Find Position One if(empty($AP_PRows1)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 1; $AP_MainPosition="Yes"; } } //Find Position Two elseif(empty($AP_PRows2)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 2; $AP_MainPosition="Yes"; } } //Find Position Three elseif(empty($AP_PRows3)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 3; $AP_MainPosition="Yes"; } } //Find Position Four elseif(empty($AP_PRows4)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 4; $AP_MainPosition="Yes"; } } //Find Position Five elseif(empty($AP_PRows5)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 5; $AP_MainPosition="Yes"; } } //Find Position Six elseif(empty($AP_PRows6)) { //If Main Position Is No if($AP_MainPosition=="No"); { //Define Variables $AP_Slot= 6; $AP_MainPosition="Yes"; } } //Find Box Position else { //Define Variables $AP_Slot= 7; $AP_MainPosition="Yes"; } if(!isset($Action)) { echo "$sorrymessage<br />"; echo "Click on the map to find pokemon!<br />"; echo "<a href='map1find.php'><img border='0' src='http://i13.tinypic.com/8104aqe.jpg'></a>"; } else { echo "You caught the Pokemon!<br />"; echo "Click on the map to find pokemon!<br />"; echo "<a href='map1find.php'><img border='0' src='http://i13.tinypic.com/8104aqe.jpg'></a>"; mysql_query("INSERT INTO pokemon_info (user_id, pokemon_name, pokemon_attack, pokemon_defence, pokemon_image, pokemon_gender, pokemon_icon, pokemon_level, pokemon_exp, pokemon_nexp, attack1, attack2, attack3, attack4, pokemon_slot) VALUES ('$ID', '$pokemonname', '$attack', '$defence', '$pokemonimage', '$pokemongender', '$pokemonicon', '$level', '$EXP', '$NEXP', '$attack1', '$attack2', '$attack3', '$attack4', '$AP_Slot')")or die(mysql_error()); } include('bottom.php'); ?> Just updated it. Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421423 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 Its still rands twice. All that did was make the script a session. Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421427 Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 Show me in my NEW code where the two rand()'s are please. Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421429 Share on other sites More sharing options...
Daukan Posted December 23, 2007 Share Posted December 23, 2007 Change this $PokemonRand= rand(1, 99); $_SESSION['rand'] = $PokemonRand; To if(!isset($_SESSION['rand']) ) { $PokemonRand= rand(1, 99); $_SESSION['rand'] = $PokemonRand; } You will need to unset $_SESSION['rand'] every time you want rerun the script with a new random number Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421431 Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 Change this $PokemonRand= rand(1, 99); $_SESSION['rand'] = $PokemonRand; To if(!isset($_SESSION['rand']) ) { $PokemonRand= rand(1, 99); $_SESSION['rand'] = $PokemonRand; } You will need to unset $_SESSION['rand'] every time you want rerun the script with a new random number Good catch. Never recognized that problem (its late here lol) Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421433 Share on other sites More sharing options...
Daukan Posted December 23, 2007 Share Posted December 23, 2007 Actually it should be this. Need to set $PokemoRand to the session value since its used throughout the script if(!isset($_SESSION['rand']) ) { $_SESSION['rand'] = rand(1, 99); } else { $PokemonRand = $_SESSION['rand']; } Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421437 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 <?PHP session_start(); include('Connect.php'); include('top.php'); $ID= $_COOKIE['UserID']; //If User Is Not Logged In if(!isset($ID)) { //Display Message echo "Sorry, you are not logged in.<br /><br /><a href='login.php'>Login</a>"; //Include Bottom File include("bottom.php"); //Exit Page exit; } $Action= $_GET['action']; $Result1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID'"); $Rows1= mysql_fetch_array($Result1); if(!isset($_SESSION['rand']) ) { $PokemonRand= rand(1, 99); $_SESSION['rand'] = $PokemonRand; } if($PokemonRand < 75 && $PokemonRand > 50) { $pokemonname="Magby"; $sorrymessage="<img border='0' src='http://i10.tinypic.com/8also6f.png'><br />Pokemon found! Want to catch?<form action='mapbeta.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(12,27); $defence= rand(15,23); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonicon="http://i9.tinypic.com/6owv9l0.png"; $pokemonimage="http://i10.tinypic.com/8also6f.png"; } elseif($PokemonRand < 100 && $PokemonRand > 74 ) { $pokemonname="Charmander"; $sorrymessage="<img border='0' src='http://i13.tinypic.com/6xvsvw7.png'><br />Pokemon found! Want to catch?<form action='mapbeta.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(15,23); $defence= rand(12,27); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonicon="http://i13.tinypic.com/6l2w8l2.png"; $pokemonimage="http://i13.tinypic.com/6xvsvw7.png"; } elseif($PokemonRand < 51 && $PokemonRand > 49 ) { $pokemonname="Entei"; $sorrymessage="<img border='0' src='http://i8.tinypic.com/7xxnyud.png'><br />Pokemon found! Want to catch?<form action='mapbeta.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(20,37); $defence= rand(23,34); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonimage="http://i8.tinypic.com/7xxnyud.png"; $pokemonicon="http://i2.tinypic.com/6wp5cmq.png"; } else { $sorrymessage="Nothing found. Keep looking."; } unset($_SESSION['rand']); $pokemonrand2= $_SESSION['rand']; //If Gender Is Male if(!isset($_SESSION['rand2']) ) { $pokemonrand2= rand(1, 99); $_SESSION['rand2'] = $pokemonrand2; } if($pokemonrand2 < 50 && $pokemonrand2 > 0) { //Define Promo Variables $pokemongender="Male"; } //If Gender Is Female elseif($pokemonrand2 < 99 && $pokemonrand2 > 50) { //Define Promo Variables $pokemongender="Female"; } //If Promo Is Ungendered else { //Define Promo Variables $pokemongender="Ungendered"; } unset($_SESSION['rand2']); //If User Has No Pokémon if(empty($Rows1)) { //Display Message echo "Sorry, you must obtain your starter first.<br /><br /><a href='obtainstarter.php'>Obtain Starter</a>"; //Include Bottom File include("bottom.php"); //Exit Page exit; } //Find Position Results $AP_PResult1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='1'"); $AP_PResult2= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='2'"); $AP_PResult3= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='3'"); $AP_PResult4= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='4'"); $AP_PResult5= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='5'"); $AP_PResult6= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='6'"); //Find Position Rows $AP_PRows1= mysql_fetch_array($AP_PResult1); $AP_PRows2= mysql_fetch_array($AP_PResult2); $AP_PRows3= mysql_fetch_array($AP_PResult3); $AP_PRows4= mysql_fetch_array($AP_PResult4); $AP_PRows5= mysql_fetch_array($AP_PResult5); $AP_PRows6= mysql_fetch_array($AP_PResult6); //Set Position Variable $AP_MainPosition="No"; //Find Position One if(empty($AP_PRows1)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 1; $AP_MainPosition="Yes"; } } //Find Position Two elseif(empty($AP_PRows2)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 2; $AP_MainPosition="Yes"; } } //Find Position Three elseif(empty($AP_PRows3)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 3; $AP_MainPosition="Yes"; } } //Find Position Four elseif(empty($AP_PRows4)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 4; $AP_MainPosition="Yes"; } } //Find Position Five elseif(empty($AP_PRows5)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 5; $AP_MainPosition="Yes"; } } //Find Position Six elseif(empty($AP_PRows6)) { //If Main Position Is No if($AP_MainPosition=="No"); { //Define Variables $AP_Slot= 6; $AP_MainPosition="Yes"; } } //Find Box Position else { //Define Variables $AP_Slot= 7; $AP_MainPosition="Yes"; } if(!isset($Action)) { echo "$sorrymessage<br />"; echo "Click on the map to find pokemon!<br />"; echo "<a href='map1find.php'><img border='0' src='http://i13.tinypic.com/8104aqe.jpg'></a>"; } else { session_unset(); echo "You caught the Pokemon!<br />"; echo "Click on the map to find pokemon!<br />"; echo "<a href='map1find.php'><img border='0' src='http://i13.tinypic.com/8104aqe.jpg'></a>"; mysql_query("INSERT INTO pokemon_info (user_id, pokemon_name, pokemon_attack, pokemon_defence, pokemon_image, pokemon_gender, pokemon_icon, pokemon_level, pokemon_exp, pokemon_nexp, attack1, attack2, attack3, attack4, pokemon_slot) VALUES ('$ID', '$pokemonname', '$attack', '$defence', '$pokemonimage', '$pokemongender', '$pokemonicon', '$level', '$EXP', '$NEXP', '$attack1', '$attack2', '$attack3', '$attack4', '$AP_Slot')")or die(mysql_error()); } include('bottom.php'); ?> Still rands twice. Can someone fix it? Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421506 Share on other sites More sharing options...
MadTechie Posted December 23, 2007 Share Posted December 23, 2007 Actually it should be this. Need to set $PokemoRand to the session value since its used throughout the script if(!isset($_SESSION['rand']) ) { $_SESSION['rand'] = rand(1, 99); } else { $PokemonRand = $_SESSION['rand']; } Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421517 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 Still deos 2 rands Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421536 Share on other sites More sharing options...
MadTechie Posted December 23, 2007 Share Posted December 23, 2007 maybe removing the 2nd random function would help $Action= $_GET['action']; $Result1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID'"); $Rows1= mysql_fetch_array($Result1); $PokemonRand= rand(1, 99); //<-- This one Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421542 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 It doesnt say that anymore, it says this if(!isset($_SESSION['rand']) ) { $PokemonRand= rand(1, 99); $_SESSION['rand'] = $PokemonRand; } This is the code <?PHP session_start(); include('Connect.php'); include('top.php'); $ID= $_COOKIE['UserID']; //If User Is Not Logged In if(!isset($ID)) { //Display Message echo "Sorry, you are not logged in.<br /><br /><a href='login.php'>Login</a>"; //Include Bottom File include("bottom.php"); //Exit Page exit; } $Action= $_GET['action']; $Result1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID'"); $Rows1= mysql_fetch_array($Result1); if(!isset($_SESSION['rand']) ) { $PokemonRand= rand(1, 99); $_SESSION['rand'] = $PokemonRand; } if($PokemonRand < 75 && $PokemonRand > 50) { $pokemonname="Magby"; $sorrymessage="<img border='0' src='http://i10.tinypic.com/8also6f.png'><br />Pokemon found! Want to catch?<form action='mapbeta.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(12,27); $defence= rand(15,23); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonicon="http://i9.tinypic.com/6owv9l0.png"; $pokemonimage="http://i10.tinypic.com/8also6f.png"; } elseif($PokemonRand < 100 && $PokemonRand > 74 ) { $pokemonname="Charmander"; $sorrymessage="<img border='0' src='http://i13.tinypic.com/6xvsvw7.png'><br />Pokemon found! Want to catch?<form action='mapbeta.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(15,23); $defence= rand(12,27); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonicon="http://i13.tinypic.com/6l2w8l2.png"; $pokemonimage="http://i13.tinypic.com/6xvsvw7.png"; } elseif($PokemonRand < 51 && $PokemonRand > 49 ) { $pokemonname="Entei"; $sorrymessage="<img border='0' src='http://i8.tinypic.com/7xxnyud.png'><br />Pokemon found! Want to catch?<form action='mapbeta.php?action=catch' method='POST'> <input type='hidden' name='Submit' value='1'> <input type='submit' value='Catch!'> </form>"; $attack= rand(20,37); $defence= rand(23,34); $level= rand(1,15); $EXP="0"; $NEXP= rand(27,52); $attack1="Flamethrower"; $attack2="Hydro Pump"; $attack3="Razor Leaf"; $attack4="Thunder"; $pokemonimage="http://i8.tinypic.com/7xxnyud.png"; $pokemonicon="http://i2.tinypic.com/6wp5cmq.png"; } else { $sorrymessage="Nothing found. Keep looking."; } unset($_SESSION['rand']); $pokemonrand2= $_SESSION['rand']; //If Gender Is Male if(!isset($_SESSION['rand2']) ) { $pokemonrand2= rand(1, 99); $_SESSION['rand2'] = $pokemonrand2; } if($pokemonrand2 < 50 && $pokemonrand2 > 0) { //Define Promo Variables $pokemongender="Male"; } //If Gender Is Female elseif($pokemonrand2 < 99 && $pokemonrand2 > 50) { //Define Promo Variables $pokemongender="Female"; } //If Promo Is Ungendered else { //Define Promo Variables $pokemongender="Ungendered"; } unset($_SESSION['rand2']); //If User Has No Pokémon if(empty($Rows1)) { //Display Message echo "Sorry, you must obtain your starter first.<br /><br /><a href='obtainstarter.php'>Obtain Starter</a>"; //Include Bottom File include("bottom.php"); //Exit Page exit; } //Find Position Results $AP_PResult1= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='1'"); $AP_PResult2= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='2'"); $AP_PResult3= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='3'"); $AP_PResult4= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='4'"); $AP_PResult5= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='5'"); $AP_PResult6= mysql_query("SELECT * FROM pokemon_info WHERE user_id='$ID' AND pokemon_slot='6'"); //Find Position Rows $AP_PRows1= mysql_fetch_array($AP_PResult1); $AP_PRows2= mysql_fetch_array($AP_PResult2); $AP_PRows3= mysql_fetch_array($AP_PResult3); $AP_PRows4= mysql_fetch_array($AP_PResult4); $AP_PRows5= mysql_fetch_array($AP_PResult5); $AP_PRows6= mysql_fetch_array($AP_PResult6); //Set Position Variable $AP_MainPosition="No"; //Find Position One if(empty($AP_PRows1)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 1; $AP_MainPosition="Yes"; } } //Find Position Two elseif(empty($AP_PRows2)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 2; $AP_MainPosition="Yes"; } } //Find Position Three elseif(empty($AP_PRows3)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 3; $AP_MainPosition="Yes"; } } //Find Position Four elseif(empty($AP_PRows4)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 4; $AP_MainPosition="Yes"; } } //Find Position Five elseif(empty($AP_PRows5)) { //If Main Position Is No if($AP_MainPosition=="No") { //Define Variables $AP_Slot= 5; $AP_MainPosition="Yes"; } } //Find Position Six elseif(empty($AP_PRows6)) { //If Main Position Is No if($AP_MainPosition=="No"); { //Define Variables $AP_Slot= 6; $AP_MainPosition="Yes"; } } //Find Box Position else { //Define Variables $AP_Slot= 7; $AP_MainPosition="Yes"; } if(!isset($Action)) { echo "$sorrymessage<br />"; echo "Click on the map to find pokemon!<br />"; echo "<a href='map1find.php'><img border='0' src='http://i13.tinypic.com/8104aqe.jpg'></a>"; } else { session_unset(); echo "You caught the Pokemon!<br />"; echo "Click on the map to find pokemon!<br />"; echo "<a href='map1find.php'><img border='0' src='http://i13.tinypic.com/8104aqe.jpg'></a>"; mysql_query("INSERT INTO pokemon_info (user_id, pokemon_name, pokemon_attack, pokemon_defence, pokemon_image, pokemon_gender, pokemon_icon, pokemon_level, pokemon_exp, pokemon_nexp, attack1, attack2, attack3, attack4, pokemon_slot) VALUES ('$ID', '$pokemonname', '$attack', '$defence', '$pokemonimage', '$pokemongender', '$pokemonicon', '$level', '$EXP', '$NEXP', '$attack1', '$attack2', '$attack3', '$attack4', '$AP_Slot')")or die(mysql_error()); } include('bottom.php'); ?> Why does it rand twice is what Im asking! Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421848 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-421953 Share on other sites More sharing options...
Xyphon Posted December 23, 2007 Author Share Posted December 23, 2007 hello? Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-422017 Share on other sites More sharing options...
MadTechie Posted December 27, 2007 Share Posted December 27, 2007 your code doesn't make logical sense.. IE.. What are you expecting to happen here ? <?php unset($_SESSION['rand']); $pokemonrand2= $_SESSION['rand']; ?> also what makes you think its randomizing twice ? maybe explain what you expecting to happen.. Quote Link to comment https://forums.phpfreaks.com/topic/82857-help-please/#findComment-424158 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.