Jump to content

NICON

Members
  • Content Count

    29
  • Joined

  • Last visited

Community Reputation

0 Neutral

About NICON

  • Rank
    Member
  1. Ignore the above I missed the variable being carried through. $x vs $no... Below is what it should have been. Thanks so much i think this got it working correctly. <?php $no = 400; $a = 0; for ($x = 1; $x < $no; ++$x) { if ($x < 200) { $a += $x * round($x + 5 * pow(4, ($x / 300))); } elseif ($x < 400) { $a += $x * round($x + 7 * pow(4, ($x / 290))); } elseif ($x < 600) { $a += $x * round($x + 11 * pow(4, ($x / 280))); } elseif ($x < 800) { $a += $x * round($x + 19 * pow(4, ($x / 270))); } elseif ($x < 1000) { $a += $x * round($x + 35 * pow(4, ($x / 260))); } else { $a += $x * round($x + 67 * pow(4, ($x / 250))); } echo round($a / 1.25); } ?>
  2. This is what I come up with base on your recomendation. However the numbers still get lost after 200: <?php $no = 201; $a = 0; for ($x = 1; $x < $no; ++$x) { if ($no < 201) { $a += $x * round($x + 5 * pow(4, ($x / 300))); } elseif ($no < 401) { $a += $x * round($x + 7 * pow(4, ($x / 290))); } elseif ($no < 601) { $a += $x * round($x + 11 * pow(4, ($x / 280))); } elseif ($no < 801) { $a += $x * round($x + 19 * pow(4, ($x / 270))); } elseif ($no < 1001) { $a += $x * round($x + 35 * pow(4, ($x / 260))); } else { $a += $x * round($x + 67 * pow(4, ($x / 250))); } echo round($a / 1.25); } ?> Below are the values for 199 through 210. Running the above gets me 2367891 vs 2302679. Something is odd here and why its running an extra time through the previous condition is perplexing to me. All the values are identical up to and including 200 using this code.
  3. So I have a very simple for loop that I am populating a list with levels and exp required to achieve the next level. I have been using a sandbox to test my output and have also created an excel sheet to replicate the data to verify the content. This code was not mine from the beginning and in creating the spreadsheet I discovered the flaw. Below is the code I am trying to fix: function experience($L, $pres = 0) { $a = 0; $end = 0; for ($x = 1; $x < $L; ++$x) { $a += $x * round($x + 5 * pow(4, ($x / 300))); } if ($x > 199) { $a += $x * round($x + 7 * pow(4, ($x / 290))); } if ($x > 399) { $a += $x * round($x + 11 * pow(4, ($x / 280))); } if ($x > 599) { $a += $x * round($x + 19 * pow(4, ($x / 270))); } if ($x > 799) { $a += $x * round($x + 35 * pow(4, ($x / 260))); } if ($x > 999) { $a += $x * round($x + 67 * pow(4, ($x / 250))); } return round($a / 1.25); } Below is the troubleshooting I am attempting to do (Modified and simplified for and while loop): //for loop $no = 200; $a = 0; for ($x = 1; $x < $no; ++$x) { $a += $x + 1; } if ($no > 199) { $a += $x + 2; } echo $a; //while loop $no = 200; $a = 0; $x = 1; while (($x - 1) < $no) { $a += $x * round($x + 5 * pow(4, ($x / 300))); $x++; if ($x > 199) { $a += $x * round($x + 7 * pow(4, ($x / 290))); } } echo $a; Upon request I can also provide snipets of the excel sheet. So the gist of what the issue I am having is this. Between level 199 and 200 the iteration of the loop is running one extra time through the initial formula. As you can tell at level 200, 400, 600, 800 and 1000 I want this formula to change so that it simplifies the amount of exp required to achieve the next level. I can not for the life of me figure out how to restrict the loop while still allowing the values 200 up to run through it for the first 199 iterations. The output I should get from the primary code for levels 199 through 201 are as follows: 199 = 200 = 201 = At level 199 I am good but for whatever reason it runs one additional iteration at the level 1-199 formula and then moves on to the 200 level formula messing up the values. Any and all help is much appreciated. I am a novice hobbyist at best and have been doing this for many, many years now but sometimes I get stumped. I chalk it up to lack of proper training and time to really be serious with it. Thanks in advance....NICON
  4. if ($number <= 9 || $yourhp <= 0) { $log[] = $number . ":&nbsp;" . $defender->formattedname . " hit you for " . prettynum($damage) . " damage using their " . $defender->weaponname . ". <br />"; } if ($number <= 9 || $theirhp <= 0) { $log[] = $number . ":&nbsp;" . $defender->formattedname . " hit you for " . prettynum($damage) . " damage using their " . $defender->weaponname . ". <br />"; } Adding these 2 if statements in limits the amount of data stored in the array... Which may have been the issue all along just way to much info in the array? I was getting a 500 error because of it.
  5. Should I toss in an if statement limiting the output from the $log to the first few and last loop?
  6. The current version running on the server is 5.5.9. It executes for roughly 30 to 40 seconds then gives an error screen. If I remove the $log in the while loop it does execute properly. Just wont give any output on the screen as to the results of this section of code.
  7. I have a while loop in a script that is running for a very long time due to the large values that are passing through it. Below is the link to the pastebin code and code embedded in this forum. Loop Statement Snipet if (!$user_class->invincible) { if (!$defender->invincible) { while ($yourhp > 0 && $theirhp > 0) { $damage = round($defender->moddedstrength) - $user_class->moddeddefense; $damage = ($damage < 1) ? 1 : $damage; if (!$wait) { $yourhp = $yourhp - $damage; ++$number; $log[] = $number . ":&nbsp;" . $defender->formattedname . " hit you for " . prettynum($damage) . " damage using their " . $defender->weaponname . ". <br />"; } else $wait = 0; if ($yourhp > 0) { $damage = round($user_class->moddedstrength) - $defender->moddeddefense; $damage = ($damage < 1) ? 1 : $damage; $theirhp = $theirhp - $damage; ++$number; $log[] = $number . ":&nbsp;" . "You hit " . $defender->formattedname . " for " . prettynum($damage) . " damage using your " . $user_class->weaponname . ". <br />"; } } $log = array_slice($log, -10, 10, true); foreach($log as $text) echo $text; } else $yourhp = 0; } else $theirhp = 0; My issue is that $yourhp and $theirhp can be in the 100's of thousands causing this to loop half a million plus times. I was curious if there was a way to only show the first few lines and last few lines of this but still retain the increment value that's created? Thanks so much in advance. NICON
  8. I was looking for a bit of documentation breaking down the post() method for jQuery thanks so much. So I tried this trying to make sense of what exactly is happening. function deleteReply(fpid) { $.post("ajax_forumdelete.php", {'reply': fpid}, function (d) { alert(d); }); location.reload(); } while keeping the $mtg function in the ajax file and it does as expected. It returns the data from that function in the browsers alert window (not sure if thats exaclty what its called) telling me: domain name says: "$mtg function plain text blah blah" Then asking for OK. When OK is pressed the page refreshes and the data is gone. I will dig deeper on how to show that text being returned in html format in lieu of that alert window.
  9. Oh thats my fault I had the other forum open in another window and clicked on this tab by accident. Should I repost or can it be moved?
  10. I have just begun dabbling with javascript as a hobby and have a very crude understanding of php so please bare with me, I am a noob! I am using a javascript onclick button to reference the function shown below. function deleteReply(fpid) { $.post("ajax_forumdelete.php", {'reply': fpid}, function (d) { }); location.reload(); } When the button is pressed and the function executes it does as it should. It deletes the forum reply post as its told and the page reloads and the post is gone! But without some sort of explanation, success message or something telling me that it did what its intended is very unsatisfying. I read around and found that an additional function is needed to give me a little message. success : function() { var x="Success"; alert(x); } Looks simple enough and one would think should be easy to incorporate but when I add it in every way shape or form I cannot get it to work. The original function wont even work after adding this. Below is basically what I am wanting to do but not quite sure how to go about it. function deleteReply(fpid) { $.post("ajax_forumdelete.php", {'reply': fpid}, function (d) { }); success : function() { var x="<?php $mtg->success("Reply has been deleted."); ?>"; alert(x); location.reload(); } } I want to use the php $mtg->success() function to echo the message in the pre defined output location and format and want to output the message after the reload... Any ideas on how to go about this?
  11. You know that's another oversight with the id but I have it set up to echo the value for each type using: <th width='20%'>Leveler OTH/OTD</th> <td width='30%'>" . $row['LevOTH'] . " / " . $row['LevOTD'] . "</td> I will tweak it a bit and see if I can get the desired output. Thanks again.
  12. Oh my I was a mile off... So I took Jacques's advice and did this $db->query("SELECT id, count(*) total, sum(case when type = 'Leveler OTH' then 1 else 0 end) LevOTH, sum(case when type = 'Mugger OTH' then 1 else 0 end) MugOTH, sum(case when type = 'Buster OTH' then 1 else 0 end) BustOTH, sum(case when type = 'Mobster OTH' then 1 else 0 end) MobOTH, sum(case when type = 'Leveler OTD' then 1 else 0 end) LevOTD, sum(case when type = 'Mugger OTD' then 1 else 0 end) MugOTD, sum(case when type = 'Buster OTD' then 1 else 0 end) BustOTD, sum(case when type = 'Mobster OTD' then 1 else 0 end) MobOTD FROM ofthes_winners WHERE userid = ?"); $db->execute([$profile->id]); $row = $db->fetch_row(true); Then I fixed the crons (day and hour). Then fixed the query on each page where that data was initially reflected. $db->query("SELECT * FROM ofthes_winners WHERE type NOT LIKE '%OTH%' ORDER BY timestamp DESC LIMIT 100"); $db->execute(); $rows = $db->fetch_row(); All is functioning perfectly and my database file is now down a table it didn't need! Thanks so much for everyone's help though.
  13. Jacques you are probably more right here than I initially intended. Its probably going to be much much easier to modify the 6 other files to make this a single table than fighting with this ambiguous query. However I would still like to know how to accomplish this for future knowledge in the event I am working with 2 very different tables.
  14. Thats my fault I wasnt thinking at all there. Okay so I have combed through but my scenario seems to be very unique. This is what I have so far. SELECT (SELECT id, count(*) total, sum(case when type = 'Leveler OTH' then 1 else 0 end) LevOTH, sum(case when type = 'Mugger OTH' then 1 else 0 end) MugOTH, sum(case when type = 'Buster OTH' then 1 else 0 end) BustOTH FROM othwinners WHERE userid = 19 UNION ALL SELECT id, count(*) total, sum(case when type = 'Leveler OTD' then 1 else 0 end) LevOTD, sum(case when type = 'Mugger OTD' then 1 else 0 end) MugOTD, sum(case when type = 'Buster OTD' then 1 else 0 end) BustOTD, sum(case when type = 'Mobster OTD' then 1 else 0 end) MobOTD FROM otdwinners WHERE userid = 19) But sql keeps giving me "The used SELECT statements have a different number of columns". Now if I remove the 4th sum row in the second SELECT I get "Operand should contain 1 column(s)". So I know I am doing something wrong but cant pin down what so I tried: SELECT id, count(*) total, sum(case when type = 'Leveler OTH' then 1 else 0 end) LevOTH, sum(case when type = 'Mugger OTH' then 1 else 0 end) MugOTH, sum(case when type = 'Buster OTH' then 1 else 0 end) BustOTH FROM othwinners WHERE userid = 19 UNION ALL SELECT id, count(*) total, sum(case when type = 'Leveler OTD' then 1 else 0 end) LevOTD, sum(case when type = 'Mugger OTD' then 1 else 0 end) MugOTD, sum(case when type = 'Buster OTD' then 1 else 0 end) BustOTD FROM otdwinners WHERE userid = 19 Removing the first SELECT completely and the query runs but only gives me results for the first SELECT id total LevOTH MugOTH BustOTH 24 319 79 77 86 18 18 4 6 6 It appears there is more data to be obtained but is not showing. I base this on the value of id and total do not equate to the values of LevOTH MugOTH and BustOTH. What am I missing here?
  15. So go with Union despite the fact the data is not being repeated or duplicated in either table. I can UNION on the userid sense that is the only info that corresponds with data from one to the other?
×
×
  • 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.