Jump to content

Recommended Posts

I am trying to basically add 2 numbers together but my math skills are lacking when it comes from reading a database. I am not 100% sure I undersdand the code here so bear with me.

 

This section reads some code...Into an array?

 

<?php
mysql_select_db("oo7",$db);

if ($mid) {
$sql="SELECT name, class, level, bonus, 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 = get_superdkp($mid);
?>

 

From there it calls the function get_superdkp and passes whats in the variable $mid to the function

 

<?php
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];
}

?>

 

Now if I added a column called bonus to the table and I want to add that into the calculation so that Rpoints gets updated with that bonus added. I am pretty sure I need to add the bonus to skpmyrow. If mid is the id of the row what do I need to add inorder for the bonus to add properly?

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/50897-simple-addition/
Share on other sites

Wow, you are persistent on this aren't ya. Way to not give up (look at my signature lol). Since your so damn determined on this, I will *try* to help ya actually get this done.  ;D

 

 

<?php
mysql_select_db("oo7",$db);

if ($mid) {
$sql="SELECT name, class, level, bonus, 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"];

$bonus=$row["bonus"];  // Add a variable for the bonus here

$level = $row["level"];
$points = get_superdkp($mid);
?>

 

 

<?php
function get_superdkp($mid) {

global $bonus; // make the bonus var global so you can access it inside this function.

  $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];

     $skpmyrow[0]+=$bonus; // here we take the existing $skpmyrow[0] var and add the bonus to it.

  $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];
}

?>

 

That *looks* right to me, try it and see what you come up with. But then again it's past 2am here so the brain ain't firing on all cylinders right now. But I hop this helps ya finally get past this issue.

 

Once you add the bonus column, you may want to delete those bonus points because if not, then they will be added every time this particular script runs, which *could* lead to massive point inflation.

 

Nate

Link to comment
https://forums.phpfreaks.com/topic/50897-simple-addition/#findComment-250342
Share on other sites

I think it will be ok with the inflation since the points are calculated from raid attendance and loot calculations in the database It seems that the bonus added "should" be correct. Who knows till I test this. Next. Can that global be passed through like the ($mid) or does it need to be like that.....just wondering. Thanks for the help

Link to comment
https://forums.phpfreaks.com/topic/50897-simple-addition/#findComment-251012
Share on other sites

yeah, you can pass the $bonus through the function like the $mid. But is there a reason you want to do this rather than just simply leaving it as a global?

 

either way it don't really matter.

 

to do it that way you'd change these items.


$points = get_superdkp($mid,$bonus); // where you call the function



function get_superdkp($mid,$bonus) { // where you define the function

Link to comment
https://forums.phpfreaks.com/topic/50897-simple-addition/#findComment-251031
Share on other sites

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.