Jump to content

Recommended Posts

I am trying to teach myself how some of my pages work so I can update them and add new features. This is part of a guild management system. My problem is that if I have a new member join and I wish to give them a welcome bonus of points. I have no way to do so without effecting all the members. Thus far the only way to add a bonus is to create a raid, list the one member and set the raid value to the bonus I wish to give. This creates a problem for the rest of the members as their attendance goes down for that fake raid that was missed.

 

Here is a snip of code that I am trying to decipher

I may be looking in the total wrong place but I think the attendance is calculated here

$dbb = mysql_connect("127.0.0.1","root","password");
mysql_select_db("oo7",$dbb);
$moddedpoints = 0;
$bonuspoints = 0;
$result = mysql_query("select * from raids where oldraid='0'",$db);
while ($myrow = mysql_fetch_array($result))
{
	$currid = $myrow["id"];
	$attresult = mysql_query("select count(rid) from attendance,raids where id=rid and rid=$currid group by rid");
	$grabrow = mysql_fetch_row($attresult);
	$raiders = $grabrow[0];

	$moddedpoints += $myrow["rvalue"]*$raiders;
	$bonuspoints += $myrow["killvalue"]*$raiders;
}
$unmoddedpoints = $moddedpoints/($currentraidbonus/$oldraidbonus);
$avaiblepoints = $unmoddedpoints - $moddedpoints - $bonuspoints;

$result=mysql_query("select round((((sum(rpoints)+$avaiblepoints)/count(*))/10)+50) as mt from members where status<>'resigned'",$db);
$myrow = mysql_fetch_array($result);
$mt = $myrow["mt"];
$mtp = $mt*10;

//if ($sort=='points') {$mtp = $mt*10;} else {$mtp=90;}

if ($sort=='points') 
{
	echo "<br><b>Max Lotto Tier : T$mt ( $mtp points)</b><br>";
}

Actually this little piece is more important

$sql="SELECT name, class, level, Rpoints FROM members WHERE id = '$mid'";
	$result=mysql_query($sql,$db);
	$num = mysql_num_rows($result);
		$row = mysql_fetch_array($result);
		$name = $row["name"];
		$class = $row["class"];
		$level = $row["level"];
//			$points = $row["Rpoints"];
		$points = get_superdkp($mid);

 

What is this $points = get_superdkp($mid);?

get_superdkp is a function, not part of php's default function list so it must exist in the project somewhere

search for "function get_superdkp("

 

*note it could be in an included file

 

as for the rest its pulling data from an mySQL database

I have deciphered the code for you and put comments above each line. All my comments are between

/*  comments here */

 

I have not changed anything in the code, so you should be able to simply cut and paste this over whats there and it should work. I hold no responsibility for broken scripts though.. I just know I did not change anything.

 

You will have to take my explanations and match it with what is happening in your application... Hope it helps some...

 

 

<?php
/* this is the mysql connection method. It connects to the database */
$dbb = mysql_connect("127.0.0.1","root","password");
/* this line selects the database you are working from */
mysql_select_db("oo7",$dbb);
/* the next 2 lines sets the variables to 0 */
$moddedpoints = 0;
$bonuspoints = 0;
/* this line makes a query selecting all items from raids where oldraid equals 0,
it specifies a db link that I am not seeing in this script  */
$result = mysql_query("select * from raids where oldraid='0'",$db);
/*  This is the loop that graps the results specified in the query above*/
while ($myrow = mysql_fetch_array($result))
{
/* Set a variable to the id grabbed from the query above */
	$currid = $myrow["id"];
/*  Run a new query; Select the amount in the db colum rid from attendance table and raids where id equals rid AND rid equals the id set from the query above group results by rid*/
	$attresult = mysql_query("select count(rid) from attendance,raids where id=rid and rid=$currid group by rid");
/* get results from the query above */
	$grabrow = mysql_fetch_row($attresult);
/*  Set a variable value of the results found in the first column of the above queries table */
	$raiders = $grabrow[0];
/*  Add moddedpoints to rvalue * variable set in line above */
	$moddedpoints += $myrow["rvalue"]*$raiders;
/* Add bonuspoints to killvalue * raiders */
	$bonuspoints += $myrow["killvalue"]*$raiders;
}
/* Sets variable unmoddedpoints to the value of $moddedpoints / ($currentraidbonus / $oldraidbonus) math in () takes presidence in the equation*/
$unmoddedpoints = $moddedpoints/($currentraidbonus/$oldraidbonus);
/* sets $availablepoints to $numoddedpoints - $moddedpoints - $bonuspoints */
$avaiblepoints = $unmoddedpoints - $moddedpoints - $bonuspoints;

/* Run another query  I think I have this right Select the results of
sum rpoints then add to $availablepoints divide by the results of count(*), then divide by 10 then add 50 then round the number to a whole number  as mt from members table where "not sure of that operator.. I think it is either less than OR greater than or it means not equal to" resigned*/
$result=mysql_query("select round((((sum(rpoints)+$avaiblepoints)/count(*))/10)+50) as mt from members where status<>'resigned'",$db);
/* Get the results from the query */
$myrow = mysql_fetch_array($result);
/* Set mt to the results of mt in query */
$mt = $myrow["mt"];
/* set mtp to $mt times 10 */
$mtp = $mt*10;

//if ($sort=='points') {$mtp = $mt*10;} else {$mtp=90;}
/* if statement comparing $sort variable to points. Dunno where either of these are gotten from. */
if ($sort=='points') 
{
/* If the statement above is true, echo this line */
	echo "<br><b>Max Lotto Tier : T$mt ( $mtp points)</b><br>";
}
?>

 

function get_superdkp($mid) {
  $dkpresult = mysql_query("select
sum(if(penalty>'0',((killvalue+rvalue)*(100-penalty)/100),killvalue+rvalue)) from raids right join attendance on id=rid where mid=$mid");
  $dkpmyrow = mysql_fetch_row($dkpresult);
  if(!$dkpmyrow[0]) $dkpmyrow[0]=1;
  $skpresult = mysql_query("select sum(-lcost)+$dkpmyrow[0] from loot where mid=$mid");
  $skpmyrow = mysql_fetch_row($skpresult);
  if(!$skpmyrow[0]) $skpmyrow[0]=$dkpmyrow[0];
  $sql=mysql_query("update members set Rpoints=$skpmyrow[0] where id=$mid");
//  return $skpmyrow[0];
  $sql=mysql_query("select Rpoints from members where id=$mid");
  $tempmyrow = mysql_fetch_row($sql);
  return $tempmyrow[0];
}

 

So im guessing it reads the database and then populates Rpoints. If i wanted to make a bonus table and add that in so it ends up in Rpoints where would I do the addition?

 

I am trying to mak it so that when I add a new member to my guild I can give them bonus DKP points. Right now the points are calculated. I tried to modify the Rpoints but they keep reverting back to the origional value. So i am guessing the only way to change them is to create a new column and add that number into the calculation.

Ok I added the column to the database and set them all to zero except one I set to 100.

For testing. So could I do this? Im just not sure where to put the query to read the bonus and where to add it.

$sql=mysql_query("update members set Rpoints=$skpmyrow[0]+bonus where id=$mid");

 

The way the row is setup

MemberName...id...bonus...Rpoint

 

Here is what I think the code is doing. I am probably not correct

<?php
// creates function
function get_superdkp($mid) {
//  sets dkpresult to killvalue+rvalue on attended raids? also adds in any penalty
$dkpresult = mysql_query("select
sum(if(penalty>'0',((killvalue+rvalue)*(100-penalty)/100),killvalue+rvalue)) from raids right join attendance on id=rid where mid=$mid");
// sets dkpmyrow to the result of the addition
  $dkpmyrow = mysql_fetch_row($dkpresult);
// if there is no result it sets to 1
  if(!$dkpmyrow[0]) $dkpmyrow[0]=1;
// adds recent loot to dkpmyrow and sets skpresult to that #
  $skpresult = mysql_query("select sum(-lcost)+$dkpmyrow[0] from loot where mid=$mid");
// sets skpmyrow to the result
  $skpmyrow = mysql_fetch_row($skpresult);
// if no data in skpmyrow set to dkpmyrow
  if(!$skpmyrow[0]) $skpmyrow[0]=$dkpmyrow[0];
// query to update rpoints in database to the id that = mid
  $sql=mysql_query("update members set Rpoints=$skpmyrow[0] where id=$mid");
// set sql to Rpoints of the id that = mid
  $sql=mysql_query("select Rpoints from members where id=$mid");
// sets that = to tempmyrow
  $tempmyrow = mysql_fetch_row($sql);
// return that to the code that called this function
  return $tempmyrow[0];
}
?>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.