Jump to content
MakeWebGames

Ranking System idea


POG1

Recommended Posts

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?

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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();
Link to comment
Share on other sites

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 #

Link to comment
Share on other sites

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());
}
}
?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...