POG1 Posted June 8, 2008 Posted June 8, 2008 im not to sure hot to create a ranking system but this is what im thinking of... <? function game_rank($ir) { $rank=0; if($ir[level] =< 5) { $rank++; } if($ir[level] =< 10) { $rank++; } if($ir[level] =< 15) { $rank++; } if($ir[level] =< 20) { $rank++; } if($ir[level] =< 25) { $rank++; } if($ir[level] =< 30) { $rank++; } if($ir[networth] =< 500) { $rank++; } $rank_array = array('#1', '#2', '#3', '#4','#5', '#6', '#7'); if($rank != $ir[rank]) { $query = "UPDATE users SET rank = ".$rank_array." WHERE userid = ".$userid; mysql_query($query); } ?> any help? Quote
Floydian Posted June 9, 2008 Posted June 9, 2008 Re: Ranking System idea you're going to want to store that rank as a number, and not with the # symbol attached to it. if($rank != $ir[rank]) { when you compare $rank to #5 for example, that #5 will become a 0 for all intents and purposes, as it will be converted to an integer. so just store $rank in that query ;) Quote
POG1 Posted June 9, 2008 Author Posted June 9, 2008 Re: Ranking System idea when you compare $rank to #5 for example, that #5 will become a 0 for all intents and purposes, as it will be converted to an integer. it compares the $rank variable not $rank_array, im not verry good with arrays so it probly wont work anyway lol i was thinking of taking the array out and just putting tan array on the output,i dunno if it would work... $ir[rank] = array('1'=>'#1 noob','2'=>'#2 ...','3'=>'#3','4'=>'#4','5'=>'#5','6'=>'#6','7'=>'#7'); Quote
Floydian Posted June 9, 2008 Posted June 9, 2008 Re: Ranking System idea when you compare $rank to #5 for example, that #5 will become a 0 for all intents and purposes, as it will be converted to an integer. it compares the $rank variable not $rank_array, im not verry good with arrays so it probly wont work anyway lol But look at how your query is: $query = "UPDATE users SET rank = ".$rank_array." WHERE userid = ".$userid; Number one, you're attempting to store the rank as #3 or whatever my rank would be, so the next time you run the script, your comparison fails. Believe it or not, I'm 110% certain of that fact. Even worse is the fact that your intentions of storing the #5 in the database table will not work in the first place and will throw a mysql error. You would know this if you had added to this line: mysql_query($query) or echo mysql_error(); Quote
POG1 Posted June 9, 2008 Author Posted June 9, 2008 Re: Ranking System idea when you compare $rank to #5 for example, that #5 will become a 0 for all intents and purposes, as it will be converted to an integer. it compares the $rank variable not $rank_array, im not verry good with arrays so it probly wont work anyway lol But look at how your query is: $query = "UPDATE users SET rank = ".$rank_array." WHERE userid = ".$userid; Number one, you're attempting to store the rank as #3 or whatever my rank would be, so the next time you run the script, your comparison fails. Believe it or not, I'm 110% certain of that fact. Even worse is the fact that your intentions of storing the #5 in the database table will not work in the first place and will throw a mysql error. You would know this if you had added to this line: mysql_query($query) or echo mysql_error(); but the rank field wouldn't be a integer so it would store the value # Quote
POG1 Posted June 9, 2008 Author Posted June 9, 2008 Re: Ranking System idea a bit plain still and i dunno if its the best way to be done but here is what i got now and it works <?php function gameRank() { global $ir,$userid,$c; $rank=0; $net=1000; while($ir[level] >=5) { $rank++; $ir[level]=$ir[level]-5; } while($ir[networth] > 1200) { $rank++; $net=$net*$ir[networth]/2; $ir[networth]=$ir[networth]-$net; } if($rank != $ir[rank]) { $query = "UPDATE users SET rank = ".$rank." WHERE userid = ".$userid; mysql_query($query) or die(mysql_error()); } } ?> Quote
Floydian Posted June 9, 2008 Posted June 9, 2008 Re: Ranking System idea but the rank field wouldn't be a integer so it would store the value # Jeezus christ, when you do the comparison if($rank != $ir[rank]) You're going to be comparing an INTEGER to a STRING That's what I've been trying to tell you, you need to just go with $rank, and only use that array when you wanna show someone their rank. ______________________ Anyways, that's a moot point as you say you have it working. I see you did go with $rank in the query in the end. You're welcome. Quote
POG1 Posted June 9, 2008 Author Posted June 9, 2008 Re: Ranking System idea $rank = int and is incremented with ++ also $ir[rank] is int... it was rank_array that wasn't a integer.. read it properly Quote
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.