SirChick Posted August 15, 2007 Share Posted August 15, 2007 i have this script: $GetEXP = "SELECT userregistration GET CrimeExp WHERE UserID='{$_SESSION['Current_User']}'"; $EXP = $GetEXP["CrimeExp"]; Echo $EXP; but its not echoing it correctly it should display the crimeexp for the user but its not working ... what have i got wrong? Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/ Share on other sites More sharing options...
cooldude832 Posted August 16, 2007 Share Posted August 16, 2007 you need to run that query <?php $GetEXP = "SELECT userregistration GET CrimeExp WHERE UserID='{$_SESSION['Current_User']}'"; $result = mysql_query($GetEXP) or die(mysql_error()); $EXP = mysql_result($result,0,"CrimeExp"); Echo $EXP; ?> however if you need more data than exp try getting it all in 1 query instead of taking 1 piece of data at a time. Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325273 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 still doesn't echo it :S this is what i have: <? //include connect info include("include.php"); // Start up the session session_start(); if (!isset($_SESSION['Current_User']) || !$_SESSION['Current_User']) { die('You must be logged in to view this page'); } //getting exp from database $GetEXP = "SELECT userregistration GET CrimeExp WHERE UserID='{$_SESSION['Current_User']}'"; $result = mysql_query($GetEXP) or die(mysql_error()); $EXP = mysql_result($result,0,"CrimeExp"); Echo $EXP; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325672 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 <? //include connect info include("include.php"); // Start up the session session_start(); if (!isset($_SESSION['Current_User']) || !$_SESSION['Current_User']) { die('You must be logged in to view this page'); } //getting exp from database $GetEXP = "SELECT CrimeExp FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'"; $result = mysql_query($GetEXP) or die(mysql_error()); $EXP = mysql_result($result,0,"CrimeExp"); echo $EXP; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325675 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 hmm it still wont echo it :S Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325676 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 try <?php //getting exp from database $GetEXP = "SELECT CrimeExp FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'"; echo $GetEXP; $result = mysql_query($GetEXP) or die(mysql_error()); $EXP = mysql_result($result,0,"CrimeExp"); echo $EXP; ?> what is echo'd Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325679 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 nothing again. its just a blank page of whiteness. table name is : userregistration field name : CrimeExp there deffinatly isnt any case sensitivity issues Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325684 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325745 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 please post your latest code (in code # tags) Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325764 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 ok ill give u all the code cos theres includes involved here, this first script decides if it will load success or failure using a rand feature. This is UnderBridgeCrimeScript.php <? //include loads session and connects to database include("include.php"); // Get the user's info from the database by putting // the user id stored in the session into the WHERE clause $GetUserID = mysql_query("SELECT * FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'"); // Fetch the row from the database if (!($row = mysql_fetch_assoc($GetUserID))) { echo "User not found!"; exit; } //assigns user's crimeexp to this field $EXP = $row["CrimeExp"]; //rand is created to choose at random if they succeed or fail.. if ($EXP <= 100) { $rand = rand(1,5); if ($rand < 3) { include('bridgefailure.php'); } else { include('bridgesuccess.php '); } } ?> then success has this script which makes a variable named $QuoteResult which i will show you how it is used further on: This is bridgesuccess.php <? include("include.php"); //FIRST RAND $rand = rand(1,5); if ($rand == 1) { $QuoteResult = "Result: You search the train station from top to bottom and find $1!";} // update the user's money to 1 more than what it was $addMoney = "UPDATE userregistration SET MoneyInHand=MoneyInHand+1 WHERE UserID='{$_SESSION['Current_User']}'"; $firstrandresult = mysql_query($addMoney) or die(mysql_error()); if (mysql_affected_rows() == 0) { die('Error ID 0001 contact admin on the Civilian forums immediately about this error!'); } // update the user's crimeexp to 2 more than what it was $addcrimeexp = "UPDATE userregistration SET CrimeExp=CrimeExp+2 WHERE UserID='{$_SESSION['Current_User']}'"; $expresult = mysql_query($addcrimeexp) or die(mysql_error()); if (mysql_affected_rows() == 0) { die('Error ID 0001, contact admin on the Civilian forums immediately about this error!'); } ?> OR the script loads failure (as the user may succeed or fail the crime) This also makes the quote for the result but will be a different string for the variable: This is bridgefailure.php <? //includes session and connect include("include.php"); //FAIL RESULT $QuoteResult = "You failed to find any money, better try some other time!"; // update the user's crimeexp to 1 less than what it was $addcrimeexp = "UPDATE userregistration SET CrimeExp=CrimeExp-1 WHERE UserID='{$_SESSION['Current_User']}'"; $expresult = mysql_query($addcrimeexp) or die(mysql_error()); if (mysql_affected_rows() == 0) { die('Error ID 0002, contact admin on the Civilian forums immediatly about this error!'); } ?> Once this is done on the main page, which the user can view, it displays the $QuoteResult, but infact it doesn't display anything, other than the last echo in the if statement below this paragraph which suggests the $QuoteResult is null and thats why i thought it was to do with the script i showed at the start of this thread. But i have suspicious feeling that its something else. This is the UnderTheBridge.php - this starts off the above scripts from a user pressing the 'DoCrime' button. <? if (isset($DoCrime['DoCrime'])){ include("UnderBridgeCrimeScript.php"); } ?> And below that in the same .php file however <div id="bv_" style="position:absolute;left:307px;top:348px;width:262px;height:64px;z-index:14" align="center"> <? echo $$QuoteResult; if($QuoteResult == 'Result: You search the train station from top to bottom and find $1!') { echo '<font style="font-size:16px" color="green" face="Arial">'; echo $QuoteResult; echo '</font></div>'; }else if($QuoteResult == 'You failed to find any money, better try some other time!') { echo '<font style="font-size:16px" color="red" face="Arial">'; echo $QuoteResult; echo '</font></div>'; }else if($QuoteResult == 'Result: You search the train station from top to bottom and find $3!') { echo '<font style="font-size:16px" color="green" face="Arial">'; echo $QuoteResult; echo '</font></div>'; }else if($QuoteResult == 'Result: You search the train station from top to bottom and find $5!') { echo '<font style="font-size:16px" color="green" face="Arial">'; echo $QuoteResult; echo '</font></div>'; }else { echo '<font style="font-size:16px" color="red" face="Arial">'; echo 'Server is having difficulties admin is working on it!'; echo '</font></div>'; } ?> its this last bit of code that is the problem it wont echo the $QuoteResult... Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325779 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 revised bridgesuccess.php <?php <? include("include.php"); //FIRST RAND $rand = rand(1,5); if ($rand == 1) { $QuoteResult = "Result: You search the train station from top to bottom and find $1!"; }else{ $QuoteResult = "Result: You search the train station from top to bottom and find NOTHING!"; } // update the user's money to 1 more than what it was $addMoney = "UPDATE userregistration SET MoneyInHand=MoneyInHand+1 WHERE UserID='{$_SESSION['Current_User']}'"; $firstrandresult = mysql_query($addMoney) or die(mysql_error()); if (mysql_affected_rows() == 0) { die('Error ID 0001 contact admin on the Civilian forums immediately about this error!'); } // update the user's crimeexp to 2 more than what it was $addcrimeexp = "UPDATE userregistration SET CrimeExp=CrimeExp+2 WHERE UserID='{$_SESSION['Current_User']}'"; $expresult = mysql_query($addcrimeexp) or die(mysql_error()); if (mysql_affected_rows() == 0) { die('Error ID 0001, contact admin on the Civilian forums immediately about this error!'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325784 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 cant have: }else{ $QuoteResult = "Result: You search the train station from top to bottom and find NOTHING!"; } because failure is on a different php file . it has to be for future reasons to do with other features..thats why i kept them seperate to avoid it getting messy. Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325787 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 OK.. if you say so but the logic says $rand = rand(1,5); if ($rand == 1) so $QuoteResult will only be set 20% of the time.. so have //FIRST RAND $rand = rand(1,5); if ($rand == 1) { $QuoteResult = "Result: You search the train station from top to bottom and find $1!"; }else{ $QuoteResult = "Result: You search the train station from top to bottom and find NOTHING!"; } or //FIRST RAND $QuoteResult = "Result: You search the train station from top to bottom and find $1!"; but hey you know best! Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325789 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 yeh i got 5 rands in total but i only shown you the first the rest are all the same structure. didnt think you would need to know all the rands. cos its like this: //rand 1 if == 1 then its this result: $Resultquote = "success1"; //rand 2 if == 2 then its this result: $Resultquote = "success2"; its too long to show you all the rands so i shown you the first one so u can see what was going on. But i duno why it wont pass the info of $QuoteResult to the the other scripts Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325790 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 OK.. if you say so but the logic says $rand = rand(1,5); if ($rand == 1) so $QuoteResult will only be set 20% of the time.. Techie Out Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325792 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 no cos it goes to the next rand if it's the other 80% of the time lol well thats what it should be doing i hope Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325795 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 read the logic UnderBridgeCrimeScript.php //rand is created to choose at random if they succeed or fail.. if ($EXP <= 100) { $rand = rand(1,5); if ($rand < 3) { include('bridgefailure.php'); } else { include('bridgesuccess.php '); //Gets here } } $QuoteResult hasn't been set yet 'bridgesuccess.php ' //FIRST RAND $rand = rand(1,5); //Random from 1 to 5 if ($rand == 1) { //if its 5 then set $QuoteResult $QuoteResult = "Result: You search the train station from top to bottom and find $1!"; } //if not 1 then $QuoteResult is still not set.. its this last bit of code that is the problem it wont echo the $QuoteResult... EDIT: also change echo $$QuoteResult; to echo $QuoteResult; Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325798 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 ok i get you now would it work doing something along the lines of : $rand = rand(1,5); //Random from 1 to 5 if ($rand == 1) { //if its 5 then set $QuoteResult $QuoteResult = "Result: You search the train station from top to bottom and find $1!"; elseif ($rand == 2) $QuoteResult = "Result: You search the train station from top to bottom and find $5!"; } etc.. untill all rand choices would effectively set the result..? Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325799 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 try this <?php $Wins[] = "Result: You search the train station from top to bottom and find $1!"; $Wins[] = "Result: You search the train station from top to bottom and find $3!"; $Wins[] = "Result: You search the train station from top to bottom and find $5!"; $Wins[] = "Result: You search the train station from top to bottom and find $10!"; $Wins[] = "Result: You search the train station from top to bottom and find $15!"; $rand = rand(0,(count($Wins)-1)); $QuoteResult = $Wins[$rand]; echo $QuoteResult; //remove this (was for testing) ?> EDIT: note if you add an extra $Wins[] = "Result: You search the train station from top to bottom and find $15!"; it will work with it note i updated the above code Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325809 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 Ok thank works ! thats great! thanks dude ! Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325815 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 please note the updated code ([1]'s to []) oow solve cool Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325817 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 oh right so the numbers aint needed Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325823 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 not in that version (i created 2 scipts that worked better and didn't need the number but i forgot to remove them) if you add more lines to they will be included ie $Wins[] = "Result: You search the train station from top to bottom and find $1!"; $Wins[] = "Result: You search the train station from top to bottom and find $3!"; $Wins[] = "Result: You search the train station from top to bottom and find $5!"; $Wins[] = "Result: You search the train station from top to bottom and find $10!"; $Wins[] = "Result: You search the train station from top to bottom and find $15!"; $Wins[] = "Result: You search the train station from top to bottom and find $20!"; $Wins[] = "Result: You search the train station from top to bottom and find $30!"; $Wins[] = "Result: You search the train station from top to bottom and find $50!"; $Wins[] = "Result: You search the train station from top to bottom and find $100!"; $Wins[] = "Result: You search the train station from top to bottom and find $150!"; so updates are easier.. with games you need to think about making updates easy!! players are demanding people!!!! Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325827 Share on other sites More sharing options...
SirChick Posted August 16, 2007 Author Share Posted August 16, 2007 hang on lol the result seems to always be : Result: You search the train station from top to bottom and find $10! //RAND $Wins[] = "Result: You search the train station from top to bottom and find $1!"; $Wins[] = "Result: You search the train station from top to bottom and find $3!"; $Wins[] = "Result: You search the train station from top to bottom and find $5!"; $Wins[] = "Result: You search the train station from top to bottom and find $8!"; $Wins[] = "Result: You search the train station from top to bottom and find $10!"; $rand = rand(0,(count($Wins)-1)); $QuoteResult = $Wins[$rand]; Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325830 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 test script create a new file paste this in <?php $Wins[] = "Result: You search the train station from top to bottom and find $1!"; $Wins[] = "Result: You search the train station from top to bottom and find $3!"; $Wins[] = "Result: You search the train station from top to bottom and find $5!"; $Wins[] = "Result: You search the train station from top to bottom and find $10!"; $Wins[] = "Result: You search the train station from top to bottom and find $15!"; $rand = rand(0,(count($Wins)-1)); $QuoteResult = $Wins[$rand]; echo $QuoteResult; ?> run it a few times i got $10 $10 $3 $5 $1 Quote Link to comment https://forums.phpfreaks.com/topic/65153-solved-get-field-using-userid-session/#findComment-325845 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.