Jump to content

requinix

Administrators
  • Posts

    15,286
  • Joined

  • Last visited

  • Days Won

    435

Everything posted by requinix

  1. By making a new thread detailing whatever it is you're asking about.
  2. ...no. You will have to actually write code. Weird, huh?
  3. The word you're looking for is pagination. Your SQL queries will look like SELECT * FROM $tbl_name ORDER BY id DESC LIMIT $offset, 20and $offset = ($page - 1) * 20 (assuming the first page is $page=1).
  4. You want to use empty cells? Normally this kind of edge stuff is dealt with by keeping the map at the edges and moving the character's sprite around (as opposed to the normal way of moving the map around and keeping the character in place). Consider moving left twice, from (2,2) to (0,2): 1. Move left: moves the map from (1,1)-(3,3) to (0,1)-(2,3) 2. The map is now at the left edge and cannot move anymore 3. Move left: moves the character over one square 1 2 3 0 1 2 0 1 2 +---+---+---+ +---+---+---+ +---+---+---+ 1 | | 1 | | 1 | | + + + + + + 2 | C | 2 | C | 2 | C | + + + + + + 3 | | 3 | | 3 | | +---+---+---+ +---+---+---+ +---+---+---+Movement is always either (a) the map if there is still space to show, or (b) the character if not. What you're saying is 1 2 3 0 1 2 -1 0 1 +---+---+---+ +---+---+---+ +---+---+---+ 1 | | 1 | | 1 |XXX | + + + + +XXX + 2 | C | 2 | C | 2 |XXX C | + + + + +XXX + 3 | | 3 | | 3 |XXX | +---+---+---+ +---+---+---+ +---+---+---+to always move the map, and fill empty spaces with the empty cell icon. It's not necessarily bad, just less common. (Makes it easier to work with non-rectangular maps though.) For that, 1. Do your query like normal 2. Tally each cell in a grid, to keep track of which squares you have cells for 3. Run through the grid, look for empty squares, and add in "empty" cells with calculated data (eg, icon URL, title, alt text) 4. Send the final result to the client Or alternatively, handle the emptiness on the client: 1. AJAX returns each cell and where it gets positioned 2. Javascript positions each returned cell 3. The map, or some parent element, has a background image, which will be visible in the areas where there wasn't a cell positioned The first approach will probably work better for your current system.
  5. So there's two elements to this: the map in the background and the position of the player. Those two are out of sync, like the character thinks it has to move towards the trees due to the map boundary yet the map can continue to move. Not knowing what you have now, this is the way I would implement it: The AJAX call to move would return something like "the map should now show the area (x1,y1)-(x2,y2) and the character is at position (cx,cy)" and the Javascript determines where to place the character. The Javascript previously retrieved map information (like boundaries and image URLs) so it can handle the entire process of rendering without the AJAX needing to return CSS values or HTML markup. Say the map is 20x20 and has boundaries (0,0)-(19,19). After movement the AJAX returns an area (0,2)-(12,14) and the character at location (4, . That location is 5 squares from the left and 9 squares from the top - not the middle of the map. The Javascript sets the map to show its background using offset (0px,64px) and positions the character at (128px,256px). After moving right a few times the AJAX may return (1,2)-(13,14) and the character at (7, ; the map is displayed with offset (32px,64px) and the character at (224px,256px). [edit] PS: I'm not 100% sure I got the numbers exactly right.
  6. No, you cannot return from the function. Just like you cannot use return in your original code. Unfortunately I can't find anything good that explains how AJAX works and what you can and cannot do with it. Unfortunate because I wanted to give you something to read (preferably something that would take more than a couple minutes) before you touched any more code. The callback function has to do a thing. It cannot return a thing. Use it to perform an action. Put the code performing an action inside the callback. 1. Why are you even using AJAX for this? Do you expect the list of users to change while the page is still open? What was wrong with the json_encode() from earlier? 2. The "callback function has to do a thing" approach will not work for that code. It's already within an event handler. Probably the most appropriate approach would be to set a variable (like but not quite how the other variables around lines 62+ are set) containing the list of users, and put that variable on line 197. But to do this best requires an answer to my first question.
  7. You cannot return the list from the uList function. AJAX is asynchronous (it's the first 'A') which means it's not executing like a normal function call but will execute eventually and somewhere else. Instead of calling uList() and then doing something with the return value, give uList() a function to call when it's ready. function uList(callback) { $.ajax({ type: "POST", url: "techs.php", success: callback }); } uList(function(users) { // do something with users console.log(users); });
  8. I'm going to copy/paste from the source: /********************************************************************** Cumulative Distribution Function POIsson distribution Function Calculates any one parameter of the Poisson distribution given values for the others. Arguments WHICH --> Integer indicating which argument value is to be calculated from the others. Legal range: 1..3 iwhich = 1 : Calculate P and Q from S and XLAM iwhich = 2 : Calculate A from P,Q and XLAM iwhich = 3 : Calculate XLAM from P,Q and S P <--> The cumulation from 0 to S of the poisson density. Input range: [0,1]. Q <--> 1-P. Input range: (0, 1]. P + Q = 1.0. S <--> Upper limit of cumulation of the Poisson. Input range: [0, +infinity). Search range: [0,1E100] XLAM <--> Mean of the Poisson distribution. Input range: [0, +infinity). Search range: [0,1E100] STATUS <-- 0 if calculation completed correctly -I if input parameter number I is out of range 1 if answer appears to be lower than lowest search bound 2 if answer appears to be higher than greatest search bound 3 if P + Q .ne. 1 BOUND <-- Undefined if STATUS is 0 Bound exceeded by parameter number I if STATUS is negative. Lower search bound if STATUS is 1. Upper search bound if STATUS is 2. Method Formula 26.4.21 of Abramowitz and Stegun, Handbook of Mathematical Functions (1966) is used to reduce the computation of the cumulative distribution function to that of computing a chi-square, hence an incomplete gamma function. Cumulative distribution function (P) is calculated directly. Computation of other parameters involve a seach for a value that produces the desired value of P. The search relies on the monotinicity of P with the other parameter. **********************************************************************/If $which == 1,- $par1 is the S value - $par2 is the XLAM value If $which == 2, - $par1 is the P value (and Q is 1-P) - $par2 is the XLAM value If $which == 3, - $par1 is the S value - $par2 is the P value (and Q is 1-P)
  9. Obviously it does exist. What is the exact error message? You've made sure that with those exact table structures and that exact trigger you're getting the same error, right? I think so but it's not clear. It sounds like you are turning a "insert a record into d_records" operation into a "create a record thing by inserting rows into d_records and h_records" operation. Or it could be that h_records is some sort of history or auditing table and you want inserts to be sort of mirrored? Or I don't know. Either way I think (not knowing your situation) I would go with a stored procedure; triggers that cause side effects in other tables and not because of something like foreign key relations feel icky to me. Too automagical. It's entirely non-obvious that inserting into d_records will also insert into h_records, but that's also due to what triggers are so... Eh, opinion.
  10. Behavior like this with a trigger? Ew. How about a stored procedure instead?
  11. ...Yes? It wouldn't be very nice if you checked out a local copy of a remote branch and it wasn't up to date.
  12. allow_url_include is about trying to do stuff like include("http://..."), which is never acceptable. It doesn't matter here. What if you try equivalent code using cURL instead?
  13. Try this: First, get rid of the stupid error_reporting(0);That tells PHP to ignore any possible errors. Then try your script and see anything happens. If not, just before the echo on line 79 add a line header("Content-Type: text/html");Then look for an error message telling you it failed because of output somewhere.
  14. Forget the developer tools. They show you what the browser interpreted in the HTML. Look at the HTML source of the page to see what PHP actually did. Also,
  15. If I may translate that, If you mean the ternary operator ? : then the answer is, While possible, in this case you shouldn't. That's more appropriate if you have "if ($condition) $var = $value; else $var = $other_value;". Your if has two statements in that else so it's really just better to leave it as is. And this is coming from someone who generally does use shorthand.
  16. I, preferring to avoid subqueries whenever possible, would do two JOINs SELECT ml.* FROM mail_list ml JOIN rosters r1 ON ml.Code = r1.Code AND r1.SectorDate = '2016-01-04' JOIN rosters r2 ON ml.Code = r2.Code AND r2.SectorDate = '2016-01-24' unless there are multiple rows in rosters for each Code/SectorDate pair...
  17. Get rid of the @ on that fopen and look for error messages.
  18. Why bother encoding it if you're just going to decode it?
  19. $data is a string. You can't do ->items on it.
  20. If you want true Word docs then I'd mention phpdocx. Not free. At my work we needed to convert HTML into something editable for our users to download, checked out options, and went with phpdocx. Does the job well enough. However, if you're running PHP from a Windows box, and don't have a problem installing Office on it too, then you can use COM to "script" Word into opening up HTML files and re-saving them.
  21. Your form is sending the data to the thank you page. For validation to work the form must be sending the data to the page where the validation is running. So a) Make your form page do the validation (which it's doing now) as well as process the form b) Make your form go to the thank you page (which it's doing now) and have the thank you page do the validation (a) is easier because (b) means that you have to find a way to shuffle the data from the thank you page to the form in case of problems.
  22. It is executing in the proper order: https://3v4l.org/7lALJ.
  23. Please don't. You'll encourage me to never post stuff like that again. I only ever use it with really, really simple stuff. Like $variable && function_call($variable);or isset($array["value"]) && $obj->property = $array["value"];You can see what it's doing at a quick glance. No thinking involved. That thing with the regex and the list() is too complicated: you have to think "okay, what is preg_match() returning and what are the values in $match and why is list() skipping the first array value" and it's just a hassle.
  24. Don't use it as a matter of practice. It's just a clever way of doing two commands at once; if the regex failed then $ip and $port would be undefined. You know $x && $y? $y doesn't get evaluated unless $x is true, and if $x is false then it does not. And since preg_match() returns 1 (which is "true") if it matches, the assignment only gets evaluated if the regex matched.
  25. Because the code on your machine is not the exact same code you posted here. Even more so because FatalErrorException is not a built-in class to PHP, which means there is some other code somewhere that defines and throws it.
×
×
  • 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.