-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
$zooelements is an array. You can't just stick an array into a string like that. Do you mean to store the JSON? Use json_encode() to turn the modified array back into a JSON string, then escape it (with mysql_real_escape_string()) before sticking it, quoted, into the SQL.
-
foreach ($output['data'] as $item){
-
"Perfectly" spaced how? 20 isn't a nice number like 19 (hexagonal) or 25 (square).
-
As the error message says, you still have a duplicate. You added a "1" to the ID but somehow there's another element that got the change. Is the XML being generated dynamically? Have you checked the XML in string form to see where "timesheet-wrapper1" appears?
-
Forms can't natively do that. 1. Put a redirect in picture.php so people accidentally going to that URL get redirected to the correct one automatically. (Which only works for GET requests.) 2. Put some Javascript in your form that will alter the form information as it gets submitted. As in you can set the target to /album/picture.php normally in the HTML, then use Javascript to change the action to /lang/album/picture (getting the lang from the form data) when it's submitted. My take on the second half: <form action="/album/picture.php" method="get" data-rewrite-action="/:lang/album/picture"> $(function() { $(document).on("submit", "form[data-rewrite-action]", function() { var elements = this.elements; this.action = $(this).data("rewrite-action").replace(/:([a-z-]+)/i, function($0, $1) { return encodeURIComponent(elements[$1] ? $(elements[$1]).val() : $1); }); }); }); POC For the www thing, RewriteCond %{HTTP_HOST} !=example.com RewriteRule ^ http://www.example.com%{REQUEST_URI} [L,R=301](replacing example.com with your domain)
-
An addon for Visual Studio to support PHP? VS.PHP is the best one I've seen, but when I checked it a couple years ago it didn't work very well. If you mean IDEs in general and not just Visual Studio then yeah, there are many.
-
Whatever XML you're transforming, or maybe the XSLT you're using, has some duplicate ids in it. That is not allowed. Each ID must be unique in the entire XML document.
-
So being able to handle white makes things awkward: it's not a hue range but both a saturation (how much color bleeds in) and lightness (grayscale) range. Playing around, it looks like good ranges are - White is S=[0.0,0.1] L=[0.9,1.0] - Gray is S=[0.0,0.1] L=[0.1,0.9] - Black is S=[0.0,0.1] L=[0.0,0.1] I figure* the best approach would be deciding what HSL ranges constitute each color, then doing some quick math to convert each component between the current color's ranges and the desired color's ranges. For example, you might say that red is H=[330,15] (meaning both [330,360] and [0,15]) S=[0.1,1.0] (so not to overlap with the grayscale) L=[0.1,1.0]; mapping a value which you've determined to qualify as "red" onto "white" could be h[white] = h[red] // hue unchanged s[white] = (s[red] - S[red,min]) / (S[red,max] - S[red,min]) * (S[white,max] - S[white,min]) + S[white,min] // convert 0.1<s[red]<1.0 to 0.0<s[white]<0.1 l[white] = (l[red] - L[red,min]) / (L[red,max] - L[red,min]) * (L[white,max] - L[white,min]) + L[white,min] // convert 0.1<l[red]<1.0 to 0.9<l[white]<1.0 That's a linear transformation - something polynomial (eg, bell curve, sigmoid) would get different results but it would take more planning and math. * I know math and the RGB and HSL colorspaces, but beyond that it's just educated guesswork.
-
jQuery - on click - find element whose class contains a variable
requinix replied to jimleeder123's topic in Javascript Help
Well, the class name is "row" + number, right? So "row" + numberThen use jQuery to do the search. Remember to put a period before the class name, otherwise you'll be telling it to look for a element. -
That technique works well (for images that aren't too large, at least) but only works because it recolors by shifting the hue of each relevant pixel (it being much easier to do this using HSL than with RGB). It's not so much a mapping of blue to green but a mapping of a range of green colors of some size to a range of blue colors of the same size. So you have to figure out two ranges: what you want to recolor from and what you want to recolor to. If all you have to work with is "blue" or "green" then you can guess by picking the midpoint of the hue range for that color and adding/subtracting roughly 60° *. Those will affect the if condition and the colorshift value, so it's probably best to make those all parameters. function recolorPants(hueStart, hueEnd, colorshift) { // correct hueStart and hueEnd for out-of-range values, both <0 and >=360 hueStart = (360 + (hueStart % 360)) % 360; hueEnd = (360 + (hueEnd % 360)) % 360; if (hueStart < hueEnd && hue > hueStart && hue < hueEnd || hueStart > hueEnd && (hue > hueStart || hue < hueEnd)) {- If the color you're starting with is RGB, convert it to HSL and use the hue value.- I suggest "bold" colors for the color choices; you can convert hue=0..360°, saturation=100%, lightness=50% to get them. * Hue ranges from 0 to 360°, and with 6 basic colors that's 60° per color and ±30°. But there's also overlap - consider how teal is greenish and blueish. So you bump that limit out to, say, 50-60° instead.
-
Cool. Are you storing them as strings or numbers? Or to be more clear, is the data type for the column in the table a string type or a number type?
-
Are you storing the phone number in your database as a string or as a number? Hint: it should be a string.
-
id="alunos[]"That's wrong. The ID should just be "alunos". The [] is only for the name.
-
set variable(s) from checkboxes - display multiple results
requinix replied to Nucleus's topic in PHP Coding Help
How you display results is your decision. So how do you want to display it? For the checkboxes, name them all clients[] and then you'll get an array of values instead of just a single value. Then use a loop to execute the command on every machine. -
Extending classes and methods question
requinix replied to NotionCommotion's topic in PHP Coding Help
A bit. So you have a parent method which does a thing, but it doesn't have the full picture (you made it protected so somebody else in the class hierarchy has to call it) while the child classes have the rest (the usethis1 and usethis2 values, which comes from within the class and doesn't need to be passed in)? Two approaches: a) The parent's method becomes a helper method with a different name, and the child classes call it with the right value. b) The parent's method is the real method, defines an abstract method (which the children implement) to get whatever value, and calls it within the method to get the value. Requires your parent be abstract. And you can use traits for a variation on either of those. That adds onto the "if something then call method" option, which is a lot like the (b) approach in that the parent's method calls other methods to get data and to perform additional actions. Anonymous functions are appealing, it's true, but there's an object-oriented design solution here that would be more appropriate. -
Extending classes and methods question
requinix replied to NotionCommotion's topic in PHP Coding Help
1. Making $extra optional with a default value needs to be handled below the parent class. If you use "dummy" a lot, that hints at those child classes having something more in common than simply that one argument, which then suggests you create another class between the parent and child which redefines those methods. 2. If the "if something then call method" pattern is very common, and kinda even if it isn't, then move that logic into the parent class. Parent has "something; $this->bla();", defines an empty bla(), and each child overrides it with their own code (ie, renaming bla_a and bla_b to bla). -
You're asking for information about why stuff is working, but you're only talking about half of the work you've done. "Altering [the images] with str_replace or preg_replace" can work fine if done correctly. That getimage.php could work fine if everything else is in line with it. So I'm not sure what to say. If you're simply migrating data and not looking too much into the future (where the images may change yet again) then I'd recommend just running a one-time script that updates all the tags in all the pages with whatever you want. Like that getimage.php stuff, which also necessitates storing the replaced image data somewhere else at the same time.
-
So, this isn't really OOP... It's still procedural code like before, except you're using functions instead of having to copy/paste code around. An OOP version would be like class Flag { private $FlagName = ""; private $pdo = null; public function __construct($pdo, $FlagName) { $this->FlagName = $FlagName; $this->pdo = $pdo; } public function CheckValue($FlagValue) { $sql = "SELECT 1 FROM flags WHERE flagname = ? AND flagvalue = ? LIMIT 1"; $stmt = $this->pdo->prepare($sql); $stmt->execute([$this->FlagName, $FlagValue]); return $stmt->fetchColumn(); } public function GetDescription($FlagValue) { $sql = "SELECT flagdescription FROM flags WHERE flagname = ? AND flagvalue = ? LIMIT 1"; $stmt = $this->pdo->prepare($sql); $stmt->execute([$this->FlagName, $FlagValue]); return $stmt->fetchColumn(); } } $pdo = new PDO($dsn, $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $intent = new Flag($pdo, 'intent'); if ($intent->CheckValue(2)) { echo "valid"; } else { echo "invalid"; }1. It could be that "a flag" is not just a name but a name/value pair, in which case you'd set up the name and value with the Flag class and then not have to pass the value into the CheckValue and GetDescription methods.2. If you did that name/value pair thing, better than querying the database in each method would be to simply load up all data when the class gets constructed - then CheckValue and GetDescription could just return values already available.
-
If you don't want it overwriting then what do you mean by having the image "changed"?
-
Need help to create dynamic php next content page.
requinix replied to Rayhan420's topic in PHP Coding Help
By making a new thread detailing whatever it is you're asking about. -
Need help to create dynamic php next content page.
requinix replied to Rayhan420's topic in PHP Coding Help
...no. You will have to actually write code. Weird, huh? -
Need help to create dynamic php next content page.
requinix replied to Rayhan420's topic in PHP Coding Help
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). -
RPG travel map grid with coords, help with x/y cords messing up
requinix replied to Analyzer's topic in PHP Coding Help
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. -
RPG travel map grid with coords, help with x/y cords messing up
requinix replied to Analyzer's topic in PHP Coding Help
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. -
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.