Jump to content

NICON

Members
  • Posts

    40
  • Joined

  • Last visited

Everything posted by NICON

  1. Those 2 id's are determined by a global variable $user->id and a defined variable earlier in the script $g defined in a class. The $g is defined by $_POST actually. So the user's id is taken from who is submitting the form and the $_POST variable is defined through the class using the id when the user hits submit.
  2. Okay that makes sense for sure. Thats the table being queried. When I use the following: SELECT COUNT(id) c, id, owner FROM cities WHERE owner IN ('21', '37') AND available = 0 My results are: When I use this: SELECT COUNT(id) c, id, owner FROM cities WHERE owner IN ('21', '37') AND available = 0 GROUP BY id, owner My results are: I want my count in this case to be 2 (my count will always be 0, 1, or 2 depending on how many rows are populated with the 21 or 37 value). These values change based on the person using this page and the owner being checked. I also want the 2 results for id and owner that I get when using the GROUP BY. So count here should be 2 and I should get output for the id and owner for both results. Hope that clears it up.
  3. I want COUNT() to be the total number of sets and the query to return the results of id and owner for each of the result sets.
  4. To explain better I am searching this table for results. There may be 100 rows in this table and never will there be more than 2 results. Some cases there will be 1 or 2 results. If there are only 1 result I want it to do this and if there are 2 results and the current result is not what I am looking for I have it loop again until I get that result. The issue I was having with the old code was that it would only loop once because it was only fetching the single row despite the fact that the count was in fact picking up 2 rows. The count has always been correct it was just not fetching the result properly.
  5. Correct me if I am wrong but by grouping wont that mean that my count will only be one unless a duplicate entry is found. In this case my query will only result in 0, 1 or 2 and will never be more than that. So now the query will give me both results as I wanted but the count is also only one even though 2 results are found.
  6. SELECT COUNT(id) c, id, owner FROM cities WHERE owner IN ('21', '37') AND available = 0 So the result for the count is 2 as shown but the result is only showing the first of the 2 rows. I have looked far and wide and cant seem to pin down why my result is incorrect. Thanks in advance for your help.
  7. I am assuming that is what is being done. I of coarse dont have the end user code or what exactly they are bookmarking but its running 100's of pages at once. I will dig into this throttling that you are speaking of and see how I can implement it into the code. Thanks!
  8. As I stated before its not a single bookmark its opening hundreds of bookmarks at once is the issue. Allowing someone to click this link on 100's of pages at once is what is unfair. The flow is appropriate but allowing someone to click so many links with one click is the issue.
  9. I agree it this site was just a general site that an every day to day user would join then I would agree 100%. However this site requires the user to be logged in to see these pages. On this page are roughly 80 different links going to different places. The idea here is to allow the user plenty of freedom and access to other parts of the site simultaneously. But this one link is integral to the site. Many users are trying to access this same link. But this one specific user has an unfair advantage because his bookmarks allow them to use this link on several users pages. The link is intended to be used and not a mass tab execution through bookmarks.
  10. So the page I am referring to is dynamic. And its only dynamic by one integer. So ?ID=1 or ?ID=2 etc.... I've been to similar pages before where the developer of that site has forced people to use the links and has essentially broken all bookmarks using that dynamic URL. I am unsure how he did it but I know that it was done. I am wanting to do something similar but without copying exactly what he did. Its not an issue of the script running its just an issue of this person is circumventing the process and creating an advantage over others by bookmarking these pages.
  11. I am trying to find a workaround for people using bookmarks and executing them simultaneously forcing a script to run thousands of times in just a second. Is there a way I can implement a token or a short bit of javascript that would force the user to use the link vs bookmarked URL pages? Sorry if I am being vague here but its really causing me issues having people doing this on my site.
  12. 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); } ?>
  13. 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.
  14. 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
  15. 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.
  16. 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?
  17. 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?
  18. 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.
  19. 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.
  20. 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.
  21. 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?
  22. 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?
  23. Yes I want to keep moving forward and not redo something right this second if it does not need to be. For the sake of function that is. All of my types are different. Very minute but all different. Each entry has a unique id. As I said both query's work independently but cant figure out how to combine them. I completely understand combining the tables is a good idea. But the data in each table is not the same. One table is updated hourly vs the other which is updated daily. So in those tables there is not duplicate data. Just a unique entry hourly in the othwinners and daily in the otdwinners.
  24. I certainly agree but this wasn't my masterpiece and at this time I am unable to change it without messing up other portions of the site.
  25. I am wanting to combine the following two query's into a single db hit. $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 FROM othwinners WHERE userid = ?"); $db->execute([$profile->id]); $db->query("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 = ?"); $db->execute([$profile->id]); The two on there own work perfect but I am unsure if using INNER JOIN or another JOIN method is going to get me what I am looking for. Both tables have the exact same columns the only difference's are in come cases the $profile->id may or may not exist and if not I will sort those with !num_rows() and the conditions for type change from one table to the other. Columns are id, userid, type, howmany, and timestamp...
×
×
  • 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.