OrganizedChaos
MIS
Hi all,
First off ***DISCLAIMER*** Still very green to PHP/MYSQL, all help is appriciated.
Ok, I am working on an app that acts as a ranking system. What I currently am doing is:
The app will track up to 30 places in a tournament, it tracks place, position, assigns points, and calculates win and power rank %..
Since I am tracking 30 possible places, I have a TON of code when I do it the way I do.. Please let me know if there is a better/more streamlined way...
// Pulls all info for player one from players db and does proper math for 1st place
mysql_connect('localhost',$username,$password);
mysql_select_db($database) or die("Unable to select database");
$query="SELECT * FROM players WHERE name= '$one'";
$result=mysql_query($query);
mysql_close();
$onename=mysql_result($result,0,"name");
$onegames=mysql_result($result,0,"games");
$oneentered=mysql_result($result,0,"entered");
$one1st=mysql_result($result,0,"1st");
$one2nd=mysql_result($result,0,"2nd");
$one3rd=mysql_result($result,0,"3rd");
$onepoints=mysql_result($result,0,"points");
$newonegames=$onegames+1;
$newoneentered=$oneentered+$players;
$newone1st=$one1st+1;
$newonepoints=$onepoints+$onepts;
$newonepercent=(($newone1st+$one2nd+$one3rd)/$newonegames)*100;
if ($newonegames >= $powerlimit) {
$newonepower=($newonepoints/$newoneentered)*100;
echo "<input name=powerone type=hidden value=$newonepower>";
}
echo "<input name=nameone type=hidden value=$onename>";
echo "<input name=gamesone type=hidden value=$newonegames>";
echo "<input name=enteredone type=hidden value=$newoneentered>";
echo "<input name=1stone type=hidden value=$newone1st>";
echo "<input name=pointsone type=hidden value=$newonepoints>";
echo "<input name=percentone type=hidden value=$newonepercent>";
echo "<input name=powerone type=hidden value=$newonepower>";
All I do for the next place is change one to two, then three etc...
Now, this pulls the data from the table that I need to update, does some math, assigns new variables and then passes the new variables to the next form. But currently I am doing this 30 times and have almost 1000 lines of code.. I thing that some type of a loop with array would be a good way to do this, but I am not sure how I would do it, it seems to be working fine, but I am concerned that it may be a problem down the road..
Any ideas?
First off ***DISCLAIMER*** Still very green to PHP/MYSQL, all help is appriciated.
Ok, I am working on an app that acts as a ranking system. What I currently am doing is:
The app will track up to 30 places in a tournament, it tracks place, position, assigns points, and calculates win and power rank %..
Since I am tracking 30 possible places, I have a TON of code when I do it the way I do.. Please let me know if there is a better/more streamlined way...
// Pulls all info for player one from players db and does proper math for 1st place
mysql_connect('localhost',$username,$password);
mysql_select_db($database) or die("Unable to select database");
$query="SELECT * FROM players WHERE name= '$one'";
$result=mysql_query($query);
mysql_close();
$onename=mysql_result($result,0,"name");
$onegames=mysql_result($result,0,"games");
$oneentered=mysql_result($result,0,"entered");
$one1st=mysql_result($result,0,"1st");
$one2nd=mysql_result($result,0,"2nd");
$one3rd=mysql_result($result,0,"3rd");
$onepoints=mysql_result($result,0,"points");
$newonegames=$onegames+1;
$newoneentered=$oneentered+$players;
$newone1st=$one1st+1;
$newonepoints=$onepoints+$onepts;
$newonepercent=(($newone1st+$one2nd+$one3rd)/$newonegames)*100;
if ($newonegames >= $powerlimit) {
$newonepower=($newonepoints/$newoneentered)*100;
echo "<input name=powerone type=hidden value=$newonepower>";
}
echo "<input name=nameone type=hidden value=$onename>";
echo "<input name=gamesone type=hidden value=$newonegames>";
echo "<input name=enteredone type=hidden value=$newoneentered>";
echo "<input name=1stone type=hidden value=$newone1st>";
echo "<input name=pointsone type=hidden value=$newonepoints>";
echo "<input name=percentone type=hidden value=$newonepercent>";
echo "<input name=powerone type=hidden value=$newonepower>";
All I do for the next place is change one to two, then three etc...
Now, this pulls the data from the table that I need to update, does some math, assigns new variables and then passes the new variables to the next form. But currently I am doing this 30 times and have almost 1000 lines of code.. I thing that some type of a loop with array would be a good way to do this, but I am not sure how I would do it, it seems to be working fine, but I am concerned that it may be a problem down the road..
Any ideas?