Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Community Answers

  1. requinix's post in Regex lookaround to prevent adding a link inside another link was marked as the answer   
    Basically, my solution is that you set up a state machine to deal with the markup. After you've split on tags and non-tags, you go through the array while keeping track of where you've been.
    But forget it. I fell for a classic mistake again: processing an HTML string like text. HTML should be treated like the structural thing it is.
    1. Load your HTML string into a DOMDocument. That will also help clean up invalid markup, which regular expressions and string processing cannot do.
    2. Loop through all the nodes. If it's a link, skip it. If it's text, do the replacement (which involves creating a new node, not simply adding a string). If it's some other element, go through its nodes recursively.
    3. When you're done, dump the document back out.
    Doing that isn't exactly the easiest thing when you're not familiar with this kind of work, so https://3v4l.org/sehhK
  2. requinix's post in Opinion? Address Verification was marked as the answer   
    For these sorts of questions it's often a good idea to see what other sites (eg, Amazon) do, then consider whether their solution makes sense to your site.
    1. Don't change stuff the user inputted without them knowing. It's confusing.
    2. The address verification service could be wrong. It's happened to me.
    Not sure what you're describing.
    Showing the "fixed" and original addresses and asking them to pick (or to edit/enter a new one) is probably the most common solution.
  3. requinix's post in Function md5_file() Limits? was marked as the answer   
    Here are some relevant facts:
    1. max_execution_time has some nuances in exactly what counts towards the limit. For instance, on Linux systems it counts only the time PHP itself is working, and therefore will not count time for disk reads which are performed by the system.
    2. The average hard drive can stream data at about 125 MB/s. An 8 GiB file would take about 8000/125 = 64 seconds to read in full.
    3. PHP's memory usage is not a perfect correlation to the underlying source - especially given that md5_file() will be performing some amount of hashing work in addition to the literal file reads.
    4. PHP claims memory in blocks. 8MB = some number of blocks taken * the memory used per block.
    Do you want to know the exact truth of what PHP is doing, or would you like to continue investigating to see if you can discover it for yourself?
  4. requinix's post in Updating Textbox2 based on Textbox1 Autocomplete was marked as the answer   
    $query = "SELECT * FROM locations WHERE location_name LIKE '{$_GET['term']}%' LIMIT 25"; Stop that. You have mysqli so use its prepared statements.
    If you want the phone number to show up somewhere then you're going to have to return it with your AJAX. Look into the documentation for your autocomplete plugin to see how you should proceed.
    For example, one possibility is that your AJAX (autocomplete.php) returns an array of [location_name, phone number], you tell the plugin that it should use the "location_name" value, and you provide a callback function when an entry is selected so you can take the phone number and set it in the textbox.
  5. requinix's post in Push notify to a browser on mobile phone was marked as the answer   
    You can do it on mobile the same way you can do it on the desktop: with AJAX polling or websockets.
    Polling is easier to implement but not instantaneous - which is probably fine for you.
  6. requinix's post in Re: july 2021 version update was marked as the answer   
  7. requinix's post in I would like to grab the ID of an edited record and insert into another table. Is this possible? was marked as the answer   
    Are you talking about project_edit.html? Is that where the form with task_lead and task_title and such are?
    That page gets the ID from the URL, right? Put the ID into the form as a hidden input so that you get a copy of that along with all the other data you want.
  8. requinix's post in I would like to grab the ID of an edited record and insert into another table. Is this possible? was marked as the answer   
    Are you talking about project_edit.html? Is that where the form with task_lead and task_title and such are?
    That page gets the ID from the URL, right? Put the ID into the form as a hidden input so that you get a copy of that along with all the other data you want.
  9. requinix's post in I need help with my select on my search box was marked as the answer   
    You entered "j" and it's listing records with user containing "j". So I don't see what's wrong with that.
    Are you talking about getting all those duplicates? It's because you're joining the login and dados_user tables together without telling MySQL how to join them together.
    You need a query that looks like
    SELECT login.user, dados_user.nome_proprio FROM login JOIN dados_user ON login.??? = dados_user.??? WHERE login.user LIKE '%$procura%' AND login.eliminado = 0  
  10. 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.
  11. 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?
  12. 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.
  13. 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']);  
  14. 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.
  15. 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.
  16. 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.
  17. 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]
  18. 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.
  19. 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.)
  20. 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);  
  21. 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.
  22. 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?
  23. 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.
    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.
  24. requinix's post in Problem with mysql retrieval was marked as the answer   
    Is "gone" nullable?
    Meaning what, exactly?
  25. 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.
  • 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.