-
Posts
15,227 -
Joined
-
Last visited
-
Days Won
427
Community Answers
-
requinix's post in Trying to find out what these examples (<FOOTER>) is called. was marked as the answer
"Tag" is still fine. It's not like that term has died off or anything. And it applies to all... well, to all tags... not just certain ones. "META tag", "HTML tag", "NAV tag", whatever.
"Element" is the other one in common usage. Means the same thing. Probably a bit more proper.
Maybe the word you're looking for is "semantic"? Because the idea of those new tags/elements is that they have a semantic meaning: while DIV is just whatever, HEADER is specifically for "a header", and NAV is specifically for navigation, and such. Makes it easier for automated processes (like search engines) to analyze a page.
-
requinix's post in Help with dropdown menu integration with switch case was marked as the answer
Is the <select> inside a <form>? Has that form been submitted? Because that's the only way PHP will be able to do this.
If you want the text to appear when you change the option without submitting a form, you need Javascript...
-
requinix's post in Which Php Function Checks For Strings That CONTAIN or NOT CONTAIN Certain Chars ? was marked as the answer
array_filter + str_contains
-
requinix's post in Recursive generator was marked as the answer
You can "yield from" another generator.
private function getTextFiles(File $file):\Generator { foreach($file->getChildren() as $child) { if($child instanceof IsTextFile) { yield $child; } else { yield from $this->getTextFiles($child); } } }
-
requinix's post in Possible with 2 ID's was marked as the answer
"Make the button go away and open another button" isn't exactly the most descriptive thing ever...
As long as something isn't visible, it doesn't really matter much whether it exists or not. The simplest thing here is going to be a sort of toggle: start with the first button visible and the second not, then "toggle" the two so the first is not visible and the second is.
1. Start with the HTML that includes both buttons.
2. Figure out how you want to hide the unwanted button and apply it now so that the second one is hidden.
3. When the first button is clicked, do whatever it takes to hide the first button and show the second.
Okay, so reading that now it doesn't seem helpful, but I'm trying to word it in a way that makes it flexible. Because when it comes to HTML and CSS and Javascript, there's always 100 ways to accomplish a task... however 95 of them are terrible.
Here's what I would do.
1. Create a CSS class for these types of button. It doesn't have to do anything (unless you want it to) and only really exists to mark these buttons as being particular types of buttons. So in that sense there's nothing to "create" per se.
2. Create a CSS class for "the active button". Apply it to the first button now, and use CSS to make "these types of buttons" which are not "the active button" be hidden. This means you control visible vs. hidden using a CSS class and not the direct style.* attributes.
3. Add Javascript for the first button that will remove its own "the active button" class and add it to the second button.
4. Add Javascript for the second button that will remove its own "the active button" (assuming you want it to be removed when clicked as well) and make the DIV you want visible; the latter should be through CSS too but it's not really that important.
Personally, if I'm dealing with behaviors that are tied to Javascript, I prefer to deal with data attributes instead of class names, but that's not very important either.
All together you get something like this:
<style> #step-container .step-button:not(.active-step) { display: none; } </style> <!-- This is a nice thing that "scopes" the buttons - using step-button or active-step outside this won't get the CSS applied --> <div id="step-container"> <button id="step1" name="button" class="btn step-button active-step">Click to Verify Information</button> <button id="step2" name="button" class="btn step-button">Show Div</button> </div> <div id="thediv" style="display: none;">...</div> <script> // Creating and running this anonymous function immediately means you can use variables without making them global (function() { // Grab these three ahead of time to make the function code nicer const btn1 = document.getElementById("step1"); const btn2 = document.getElementById("step2"); const thediv = document.getElementById("thediv"); // Add event listeners through code instead of putting them inline with onclick attributes btn1.addEventListener("click", () => { // Use .classList to add and remove classes instead of going through the .className string btn1.classList.remove("active-step"); btn2.classList.add("active-step"); }); btn2.addEventListener("click", () => { btn2.classList.remove("active-step"); // Literally removing the "display" override is better than forcing it to be block/inline/whatever it's naturally supposed to be thediv.style.removeProperty("display"); }); })(); </script> This is closer to the sort of modern stuff that we can do nowadays; the above isn't actually quite ideal, but it's a good step-up from the sorts of stuff we had to do 10 and 20 years ago with inline event handlers and quick-and-dirty Javascript.
-
requinix's post in About the use of the __DIR__ controller. was marked as the answer
__DIR__ is a "magic constant" (it's a constant with a value that varies) that is the directory of the file you put that code in. That's all there is to it. Period. Super simple. Nothing to do with URLs. Nothing to do with MVC design. Nothing to do with your website, really. Just a directory path.
-
requinix's post in SoapServer with operation name with dash was marked as the answer
You don't, and whoever created that WSDL was dumb to not consider potential situations like this.
You can, however, use the magic __call method to intercept calls to methods that don't exist, and create a properly-named method to do the work.
class MySoapServerClass { public function __call(string $method, array $args) { return match ($method) { "ProvideDocument-b" => $this->ProvideDocumentB(...$args), }; } private function ProvideDocumentB(...) { ... } }
-
requinix's post in If statements with icon was marked as the answer
So with this,
<a href="<?php print wp_kses_post($item['linkedin']); ?>"><i class="fab fa-linkedin-in"></i></a> the link is wp_kses_post(...) and you don't want to show the <a> if the link is empty.
Get the value of the link into a variable, use it with the if statement, then only show the <a> if not empty.
<?php $linkedinlink = wp_kses_post($item['linkedin']); if ($linkedinlink) { printf('<a href="%s"><i class="fab fa-linkedin-in"></i></a>', htmlspecialchars($linkedinlink)); } ?> Remember to use htmlspecialchars when you do not know if a value is 100% safe for HTML.
-
requinix's post in CRUD create form, output PHP was marked as the answer
1. Don't use mysqli_multi_query because you're running the three queries by themselves individually already.
2. Don't create queries where you put $_POST values directly into the SQL. It's extremely unsafe. Use prepared statements instead.
-
requinix's post in CSS grid question - flow around an element was marked as the answer
The template does one name per cell so you can't overlap things on their corners.
grid-area is shorthand for grid-row/column-start/end, so you could explicitly set the column-end to be "right". That'll stretch it out over that column, but text won't wrap and I don't know if there is a way to essentially "float" that right element.
So what you could do, given you know the size of the columns and rows (or do you?) is to create a floating div inside the content that positions where the overlapping right cell is.
https://jsfiddle.net/e1hg05af/
-
requinix's post in PHP 8.x and PEAR - Windows was marked as the answer
Some Googling suggests that there's a weird and long-standing issue with the .phar such that you can't download it from a browser but need to use a tool like curl.
PHP itself might work too.
> php -r "copy('http://pear.php.net/go-pear.phar', 'go-pear.phar');"
-
requinix's post in [cakephp] Database driver Cake\Database\Driver\Mysql cannot be used due to a missing PHP extension or unmet dependency. Requested by connection "default" was marked as the answer
It would appear that the driver cannot be used due to a missing PHP extension or unmet dependency.
Do you have the pdo and pdo_mysql extensions installed?
-
requinix's post in Fulltext searching was marked as the answer
FULLTEXT searching just does not do that. It doesn't offer particularly sophisticated features: it's oriented towards taking an input list of words and trying to find things that are relevant to those list of words.
"M/C" isn't going to work because those aren't words. Prices aren't going to work because those aren't words. "Within 10 words of each other" isn't an option.
-
requinix's post in Upgrade website from 7.3 to 8 was marked as the answer
Sure: upgrade to PHP 8 and see what it complains about. Not on the real site, of course, but in some development version of it. That's really the most effective method.
I don't know what "tags" are, but the online documentation has migration guides.
Go through each guide in sequence; if you want to upgrade to latest, which is 8.2, then you need the 7.3->7.4 and 7.4->8.0 and 8.0->8.1 and 8.1->8.2 guides.
-
requinix's post in Subracting a number from decimal value in mysql was marked as the answer
DECIMAL(65,0) means it can store a number with 65 digits and 0 after the decimal point.
-
requinix's post in Structure for Small Custom System was marked as the answer
You already know the answer to that: some point before you end up with 116 functions in a 2600+ line file.
As for where "before" is, that's tricky. Because despite what many others will say, sometimes having complicated things contained in one single place makes them easier to understand than if they had their components spread out across multiple locations - but having that as an exception to the rule also lends itself to being an excuse to ignore the rule.
The simplest approach is what I hinted at: separate by category, or purpose. With 116 functions there are going to be a much smaller number, perhaps a dozen, of groupings. Like notes functions, and activity functions. Even if you only had one "createNote" note function, the fact that it's a different subject matter than activities warrants having it in its own place.
The other answer is that good code design won't let you create massive utility classes to begin with - no offense. Following principles like SOLID (its "single-responsibility principle" is what that whole categorization thing is essentially about) or DRY will naturally encourage you to break things up as a side-effect.
-
requinix's post in Why does directory listing wih array_push gives warning "the first argument is not an array" ? was marked as the answer
The second argument to array_push is the item you want to push. It is not an array of items you want to append. So that's a problem, though a bit separate from what you're looking at now.
How about the return value?
-
requinix's post in How to reflect the ball at an angle? was marked as the answer
You don't need physics - just a simple if/else. Assuming you're talking about vertical and horizontal walls (like those of the containing box).
Give it a thought yourself and you'll probably find it's easier than you expect. You're already calculating the ball's "angle" using X,Y components so consider what happens to them if you have, say, a velocity {x=1, y=2} at the time when the ball encounters a horizontal wall...
-
requinix's post in Ratings in database ala Amazon. How many of each? was marked as the answer
Does it have to be in your results? It would be really easy to just write a tiny bit of code that uses 0 if there aren't any ratings of a particular star count.
-
requinix's post in Smarty template & PHP 8.1, TEXT: Function strftime() is deprecated was marked as the answer
Huh, it's actually doing the thing I thought it wasn't...
Only thing left I can think of would be skipping E_DEPRECATED messages.
set_error_handler("error_handler", E_ALL & ~E_DEPRECATED);
-
requinix's post in need help to figure something was marked as the answer
I'll give this one more try:
1. I've already mentioned that include() will return a boolean. Specifically, true if it was able to include the file and false if it was not.
2. You are using <?= tags instead of regular <?php. Remind yourself of what the special <?= form does.
Do you know what happens when you combine those two together?
-
requinix's post in JS Front End was marked as the answer
"Best practices" only apply to very specific questions. There is no single answer to "how do I make a login page" but there are a couple for "how do I handle password resetting".
If you're looking to learn frontend Javascript then the most common answer is React, but there are also others like Vue and Angular that have a following.
-
requinix's post in PHP 8.1 Showing Warnings was marked as the answer
You have code that ends up doing something like this:
$variable = false; echo $variable->current; That is wrong and broken. It needs to be fixed, and making the warnings go away does not do that.
-
requinix's post in category_page restriction was marked as the answer
Looks good to me.
There are a few online tools to help build and test regular expressions, like if you want to try running a few inputs through the regex to see if they match. regex101.com and regextester.com come to mind.
A router takes a request and routes it to a different location or resource or code path. That sounds like what you're doing.
-
requinix's post in Bring navbar at center CSS was marked as the answer
So I guess you figured it out?