eqnastun Posted May 11, 2007 Share Posted May 11, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/50897-simple-addition/ Share on other sites More sharing options...
tauchai83 Posted May 11, 2007 Share Posted May 11, 2007 ???? the title should change to intermediate addition and NOT simple addition. haha Quote Link to comment https://forums.phpfreaks.com/topic/50897-simple-addition/#findComment-250329 Share on other sites More sharing options...
chronister Posted May 11, 2007 Share Posted May 11, 2007 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. <?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 Quote Link to comment https://forums.phpfreaks.com/topic/50897-simple-addition/#findComment-250342 Share on other sites More sharing options...
eqnastun Posted May 12, 2007 Author Share Posted May 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50897-simple-addition/#findComment-251012 Share on other sites More sharing options...
chronister Posted May 12, 2007 Share Posted May 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50897-simple-addition/#findComment-251031 Share on other sites More sharing options...
eqnastun Posted May 12, 2007 Author Share Posted May 12, 2007 It looks prettier /shrug Quote Link to comment https://forums.phpfreaks.com/topic/50897-simple-addition/#findComment-251047 Share on other sites More sharing options...
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.