-
Posts
15,227 -
Joined
-
Last visited
-
Days Won
427
Community Answers
-
requinix's post in Form mail help to a beginner was marked as the answer
You check if the value "is set". Being empty or being zero counts as "set".
If you want to check that the value is >0 then try doing exactly that.
It is very much possible. You're misunderstanding the recommendations to use loops and otherwise change how your form processing code works.
-
requinix's post in Trigger change event was marked as the answer
1. Events do not cause recursion, and so shouldn't cause any stack size problems.
2. I don't see any recursion in the code.
What's all the code for this form?
-
requinix's post in 6 minute error in date-times was marked as the answer
So if I tried to format as "mmm", what would it do? Months? Minutes? Combination of both?
Check the documentation, or look up earlier in your code to see what you should be using instead.
-
requinix's post in Function call in foreach() was marked as the answer
Right. And the function is a good decision to reduce duplication. What I mean is, this doesn't have to be much more complicated than just
$firstname = clean_names($_POST['firstname']); $lastname = clean_names($_POST['lastname']); $username = clean_names($_POST['username']);
-
requinix's post in Need help with class? was marked as the answer
All that code in InitializeData should be inside the constructor instead. There is no need for InitializeData to exist. It forces you to call that method every time you create a new instance of MainframeData, and if you forget then you get problems like the one that started this thread.
If you need to set up appVer and appTitle when the object is created then you should be literally setting up appVer and appTitle when the object is created.
-
requinix's post in Refresh paeg after query finished was marked as the answer
This is a link to the page. The link does not matter once you arrive on that page. If you want to do something with that page then the link to the page is not where you should be focusing your efforts.
If the scraping is all done in PHP and there is no output of any kind (or you can remove all of the output already there) then all you have to do is use a header() redirect at the end of the script.
-
requinix's post in Submitting form with more than one submit button was marked as the answer
So... do that? You can tell what button is pressed, so if they pressed the Delete button then make the code do what you want it to do.
-
requinix's post in Bilingual mod_rewrite was marked as the answer
RewriteRule ^(hu)/([^/]*)\.html$ /index.php?lg=$1&c=$2 [L]
This URL is very similar to the /vojvodjanski/drustvo.html because they are both "/" + word #1 + "/" + word #2 + ".html". If you want word #1 "hu" to be special then you must put this RewriteRule before the [^/]+/[^/]+.html RewriteRule.
If you want another language, like sk, then
RewriteRule ^(hu|sk)/([^/]*)\.html$ /index.php?lg=$1&c=$2 [L]
-
requinix's post in Cannot execute another php script (Using XAMPP on Windows 10) was marked as the answer
You mean are most questions we get here about Javascript? No, it's mostly PHP, but it's mostly PHP in a web context. As in PHP is running on a website and people are visiting it in their browser. Which means Javascript is an option. But sometimes there are non-web PHP questions.
I don't know which one of those this thread is yet...
If you want to run something every X minutes then the standard answer is to use cron: every *nix server has it, it runs in the "background", meaning it's not driven by or reliant upon users taking specific actions (such as "keeping the browser open so something can do AJAX requests"), and you can still do just about anything you want with PHP.
For the 30 minutes one, you make a script that runs whatever database queries it needs. I don't know what it's supposed to do if the value changes? Then you tell the server (exact steps vary) that you want to run some command-line program (ie, PHP with the path to your script) every 30 minutes.
For the 10 minutes one, you make a script that runs whatever database queries it needs. Then you tell the server you want to run a second program (also PHP) every 10 minutes.
-
requinix's post in PHP reloading when clicking back button was marked as the answer
Given that browsers tend to decide for themselves whether to use a cached version of a page or not (though you can influence that), the most reliable method would be to do two things:
1. Randomize the order of questions in a reproduceable way. shuffle() is always random and you can't control it, but if you moved the randomization into your SELECT query (which is possible) then you could get the same "random" ordering every time. You would then need some identifier in the URL that you can use or turn into a number suitable for this purpose. Exactly how depends.
2. Instead of telling people to go back, give them a link to click to "return" to the questions. This is a great idea because not only do you eliminate the Back button problem, you can give people a link that shows what their answers were and which ones were correct or incorrect. (If you want to.)
-
requinix's post in Move an input with Jquery after setting as a variable was marked as the answer
You can't mix HTML strings and HTML elements together like that.
Construct the HTML as a string if you wish, if that's easier to do, but you'll have to .append fn and whatever into it separately. For example,
var row = $("<div class='row'>...</div>"); row.find("label[for='basic-url'] + div").append(fn); $(".content").append(row);
-
requinix's post in javascript select option by data-value was marked as the answer
Somewhere in your code you wrote "new Choices(...)". Hopefully you assigned that to a variable, like the example does with "const example =".
Call setChoiceByValue("AFG") on that variable.
-
requinix's post in Can not access to the website and no content displayed was marked as the answer
The error message seems to rather clearly indicate that there is no "app" database. Have you tried looking into that?
-
requinix's post in for loops, learning was marked as the answer
A loop isn't a mystical thing that does work for you. It's merely a tool. A means to an end.
So the question you should be asking is whether something, a page or a function or whatever, needs loops to perform its necessary tasks. And odds are that if you have more that one of some things then you'll need a loop to process them.
So you have a one-to-many relationship? That is, every single row in "table" has one or more corresponding rows in "anothertable"?
You're absolutely right to consider an INNER JOIN. It will be far, far more efficient for you and your database if you issued one single query to retrieve all the data at once instead of one for the first table and another N for the second table.
But you're also right that it won't be obvious where one id/name stops and one id/name begins...
...unless you do what is probably going to sound obvious in retrospect: make the query also return the id and name.
SELECT t.id, t.name, at.field1, at.field2 FROM table t JOIN anothertable at ON t.id = at.field3 ORDER BY t.name, at.something When you go through those results (with a loop), track the previous id and keep an eye out for when it changes. Note that sorting the results is key for this to work, since otherwise there's no particular guarantee on whether all the rows for a given table.id show up together, but it's also probably something you'd want to do anyways.
Essentially,
previous id = null foreach row { if current id != previous id { new heading } print row previous id = current id }
In practice it tends to be a little more complicated than that, depending on what kind of output you want - especially if it's HTML, and especially especially if you want syntactically valid HTML.
-
requinix's post in Problem with mysql retrieval was marked as the answer
Is "gone" nullable?
Meaning what, exactly?
-
requinix's post in Macro substitution was marked as the answer
If your code has and $$s in it then it is doing something terribly wrong.
Use an array for the postal codes like a normal person.
-
requinix's post in PHP https with $_SESSION send to another page was marked as the answer
Browse around your site and make sure the browser always says the page is encrypted, or at least it never says it isn't encrypted.
With Chrome, for example, a padlock icon on the left of the address bar means it's HTTPS.
-
requinix's post in Has something changed that I am not aware of? was marked as the answer
I can't tell what your other account is. What's the username or email? You can post it or PM me.
I'm being stupid. It should be obvious what the original account is.
I do see the account being locked from too many unsuccessful login attempts from 37.147.174.213, but that lock has since expired (while the site was offline). You should be good to go now.
I can't really speak to the support ticket thing... Nibble Netwrx owns PHP Freaks so that's why you got that email from them.
-
requinix's post in Cron Job API Integration was marked as the answer
You'll probably have to make some other minor changes so that this script can run from a cronjob, but
Essentially the change you need to make is to take all of that code, which works for a single page of data, and stick it inside of a loop that goes through all of the pages. Starts at page 1 (or perhaps 0), runs the code that you have now but edited to use that page number, then the loop moves to the next page and starts again until eventually there are no more pages.
-
requinix's post in Downloading selected multiple file was marked as the answer
Look at the examples and maybe try some Google searches for using PHP to download multiple files with a ZIP archive. There's a lot of information out there and it isn't too hard to find samples you can reference.
-
requinix's post in Redirect domains to a URL+domains was marked as the answer
What? Sure you do: that second server you were planning to use. The one where the domains redirect to, and where you were going to redirect from.
Take that, add a virtualhost for a catch-all domain (so any domain that doesn't match some other known site), then give it a redirect to go to destinationtarget.com/(requested domain). It's one configuration that handles the redirects for every single domain you throw at it - assuming you all want them to use the same pattern for the redirect.
Then you change the DNS for the domains you want to redirect from such that they resolve to that second server. Browser will look up "domain1.com" or "domain2.com" or "domain3.com", all of them resolve to that second server, browser asks the server for the webpage at that domain, server responds with a redirect to destinationtarget.com.
In fact, that "second server" can simply be whatever server hosts destinationtarget.com. I mean, this redirect business is very lightweight. It's not going to add any noticeable load to anything.
So there. You have a server that hosts destinationtarget.com. Give it a new configuration for a catch-all domain that does the redirect I said, then update the domains to point to that server. And if you decide to handle some redirected domains differently then you don't have to update DNS for anything.
-
requinix's post in Executing time consuming functions in an EventLoop was marked as the answer
In this case it's about using the generator as a coroutine. Generators can suspend execution and return to some caller, then that caller can have the generator resume.
The use case here is that your doWork becomes a generator, and it yields (suspends) every email or so. When it suspends ReactPHP would have a chance to execute as it needs (ie, run through the event loop), and when it's ready it has doWork continue. Rinse and repeat until hair is sufficiently washed.
https://3v4l.org/qlXCj
As long as doWork is running, ReactPHP's loop will not execute. Because it's not truly asynchronous - it just looks that way.
The basic problem you have is that doWork takes too long. The basic solution is to split the work according to whatever is not "too long". Since your metric is time, I suggested running work until some suitable amount of time has passed. Like one second.
doWork is probably self-contained, right? It determines what work needs to be done and does it. You'd refactor that so that determining the work to be done happens before doWork, then doWork goes through that set until either too much time passes or it runs out of stuff.
class DoesWork { private $work = []; public function __construct() { $this->work = ???; } public function addWork($item) { $this->work[] = $item; } public function doWork() { // exact code varies, but basically... $now = microtime(true); $end = $now + 1; while ($this->work && $now < $end) { $item = array_shift($this->work); // whatever $now = microtime(true); } } public function hasWork() { return !empty($this->work); } } // setup $worker = new DoesWork(); // inside the event loop, if ($worker->hasWork()) { $worker->doWork(); } If you look closely, you'll notice the code structure looks similar to what was in that 3v4l link...
-
requinix's post in html table with data from 2 sources was marked as the answer
That is the correct answer. Why do you not want to do it?
-
requinix's post in For Each Loop on Common Value in DB was marked as the answer
First you'll have to sort the results by the type. Because otherwise stuff will bounce between one type and another. Then you should probably sort by a secondary another field - I suggest the item name, since that's what the user sees.
Really, most of the time you're running a query for data that gets displayed to a user, you'll want to sort by something. Even if you don't need anything grouped or sorted alphabetically, picking and sorting by a unique column (like an ID) guarantees that you'll get the same data in the same order every time.
Anyway, when you have that sorting, your loop will need to know when the type changes. That means remembering what the previous one was.
Get yourself a variable for it. Start it off empty. Inside the loop, if the current type doesn't match the previous type (and the first row definitely will not) then that means you need to start a new group. If there was a previous type then there was a previous <optgroup> already going for it and you'll need to close that out, then either way you start the new <optgroup>.
Finally, you need to think about that last group. When the loop finishes you'll have been working on one group but the <optgroup> will still be open. So close that one out too.
-
requinix's post in Can't escape this quote was marked as the answer
HTML doesn't do backslashes for escaping characters. You have to use an entity for it.
'label' => __( 'Title