Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Community Answers

  1. 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?
  2. 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.
  3. requinix's post in Problem with mysql retrieval was marked as the answer   
    Is "gone" nullable?
    Meaning what, exactly?
  4. 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.
  5. 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.
  6. 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, 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
    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...
  11. 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?
  12. 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.
  13. 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
  14. requinix's post in Can I access $_GET['id'] if the page is html? How does this code do it!? was marked as the answer   
    "Reliable"? If the code is solid then sure, it's reliable.
    Method I use:

    var id = (document.location.search.match(/[?&]id=([^&]+)/) || [])[1] || ""; And if you don't have access to PHP then it doesn't really make sense to ask this in the PHP forum, does it?
  15. requinix's post in Controller and Model Paradigm was marked as the answer   
    The model represents the data, so it's often a database model but it can also be a so-called "business" model: represents data as the application needs to use it, and would use simplistic database models to get the data it needs so it isn't connected directly to the database. But it's not too common to have both.
    However a database model isn't limited to strictly reading from and saving to the database. Some people do that, personally I don't. Really the model is the central place for dealing with data - yes, working with the database is a key component of that, but it can also involve testing the data (eg, verifying login credentials) or manipulating the data (eg, changing a user's password) or many other actions.
    So yes, the model should not be able to log a user into the application because that is beyond the scope of managing its data. It should have a method to test login credentials, because that is directly related to its control of the data, but the controller is what would do the actual logging-in with the session and cookies and whatnot.
  16. requinix's post in Updating quantity if item is already in cart was marked as the answer   
    Oookay, so we're going further back into the basics of PHP than I was expecting.
    0 == false. If you try to say "if (0)" then it will always execute the else branch. So if you say "if ($itemExists)" and that variable is 0 then it will also always execute the else branch.
    Since your function can return 0 or false, and you want to know if the value is not literally false, then you need a literal - aka "strict" - comparison.

    if ($itemExists !== false) {On top of that is your latest post. 
    One equals sign is assignment. Two equals signs are a loose comparison, where values are compared in spirit without regard to their exact type. Three equals signs are a strict comparison, where values must be the same type for them to possibly be the same.
    That if statement you have will assign the value of "0", which is a string by the way and not a number, to the variable $itemExists and then try to decide if that same value is loosely true. Which it is not. And so the else branch will execute. Again.
    If you fixed your condition to use two equals signs for a loose comparison then it would work for items in the first position in the cart, except now every other case would be thoroughly messed up.
    If you fixed your condition to use three equals signs then we'd be back to the original situation of the else executing every time, but this time it would be because the function never returns the string "0".
  17. requinix's post in Obtain PHP array definition script based on JSON was marked as the answer   
    Try var_export.
  18. requinix's post in securing file uploads from a form was marked as the answer   
    Linux allows every character. 
    Store the original name as metadata with the upload. Actually name it on your server as something completely different.

    See above.  

    If you want.  

    The type is not safe to use. Don't even look at it. To detect type yourself, the file extension is most important and MIME identification can also help.  

    Of course.
  19. requinix's post in post form data (textarea) as file was marked as the answer   
    The default is actually application/x-www-form-urlencoded. That's the normal key=value&key=value&... syntax you should recognize. multipart/form-data, mostly used for file uploads, is a far less compact format but better suited for lots of content.
    Doing this as a fake file upload really sucks. Use the Blob and FormData classes.

    var fd = new FormData(); var blob = new Blob([/* textarea contents */], { type: "text/plain" }); fd.append("nta_big", blob); var xhr = new XMLHttpRequest(); xhr.open("POST", /* url */, true); xhr.send(fd);Untested but should be close. 
    With jQuery you might be able to use a Blob with its AJAX methods, as in

    { "nta_big": blob }as part of the sent data.
  20. requinix's post in Ajax, multiple form elements was marked as the answer   
    onchange="showdata(this.value)"All that does is send the value of whatever element to the function. Not only will the function not know which element is calling it, the function needs all three values at the same time. 
    There are many ways to do this - personally I would pass the function not the values but the form itself. The function can then get the values from the form.

    onchange="showdata(this.form)" <script> function showdata(form) { var project = form.fm_project.value, module = form.fm_module.value, stage = form.fm_stage.value;Then update the rest of the function to use those variable names. Because they're much more descriptive than stuff like "stra".
  21. requinix's post in Preventing scientific notation in a string was marked as the answer   
    Use sprintf to get a different string representation for $const1.

    $const1string = rtrim(sprintf("%.20f", $const1), "0");
  22. requinix's post in Unable to post in 'Website Critique' was marked as the answer   
    Try now.
  23. requinix's post in I can't edit my profile about me section. was marked as the answer   
    Try now.
  24. requinix's post in getting Undefined Index error. was marked as the answer   
    Presumably the error is pointing to

    $user_id = $_SESSION['user_id']; //We'll get the user_id from the session"Undefined index" means there is no user_id in $_SESSION. Either the user is logged out or your code is looking at the wrong array index.
  25. requinix's post in Link With Anchor Causes Tab-Formatting JS To Fail was marked as the answer   
    Clicking the link puts the #anchor in the URL. Refreshing the page will keep that URL but reset the page to the state it was delivered by the server.
    a) Clicking the link should not update the URL. Refreshing will go back to the original state.
    b) Update the URL, and include some Javascript that runs on page load to check if there is an #anchor and update the page as needed.
  • 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.