Jump to content

Jacques1

Members
  • Posts

    4,207
  • Joined

  • Last visited

  • Days Won

    209

Everything posted by Jacques1

  1. Let's skip the guess-what-my-problem-is game and just say what's wrong. If you aren't getting an error message, enable exceptions, turn your error reporting all the way up and either display the messages (during development) or log them (in production). You cannot mix named and positional parameters. Pick one. You also have to bind all parameters.
  2. I'm not sure what you're trying to tell me. The process I've described is purely server-side.
  3. PHP doesn't know anything about “containers”. If you want to render different pages with the same index.php script, you have to implement that yourself. You'll need to pass a page identifier as a URL parameter (URL rewriting can prettify this), and then you need code to choose the right page for the given parameter (this can be implemented with an array or a long if statement, for example). A smarter approach is to use a template engine which supports inheritance (like Twig). Then you can define a base template with a header and/or a footer, and each page can insert its specific content into that template.
  4. There are no comma-separated conditions. The commas are for the arguments of the isset() function, which is perfectly valid. Of course the === true comparison is nonsensical, because isset() already is a boolean function which either returns true or false. You cannot make a boolean “more boolean”. As to the original problem: Something is very wrong here. The mysqli_report() call enables mysqli exceptions, which means PHP should abort the script in case of a mysqli error and not return false. Since you do get false, you're either looking at the wrong code, or the code you've posted isn't the one you're actually using.
  5. RTFM [To everybody else: The OP is a known troll. Think twice before you invest any time.]
  6. Once again: Different jobs have different requirements. There is no law saying what is and what isn't “OK” for a web developer. Each company has its own idea of programming, and the trick is to find the one which matches your personal preferences. Go out and apply for real jobs. Some companies won't hire you. Some jobs will be boring. You may even realize that professional programming isn't like you hoped it was. This is all perfectly normal, and it will tell you a lot more than an abstract discussion in an anonymous online forum.
  7. Before you start writing code, you need to actually understand how PDO and prepared statements work. There are excellent tutorials which explain this in great detail, so going by trial-and-error is complete nonsense. First off, the purpose of a prepared statement is to pass values to a query or speed up multiple query executions (though the benefit of this is debatable). When you neither have external values nor want to execute the query more than once, then a prepared statement doesn't make sense. Just use a plain old query. $total_posts = $db->query('SELECT COUNT(*) FROM posts')->fetchColumn(); Secondly, prepared statements have to be executed. The prepare() method merely creates a statement, it doesn't run any queries. That's what execute() is for. There are three necessary steps: Create the prepared statements. Bind values to it (this can usually be combined with the execution). Execute the statement. Third, a blank page means you don't understand how error reporting works, or the configuration is messed up. This is your local development PC, right? Then turn the error reporting all the way up, and enable display_errors. In production, you log the errors instead. PHP doesn't just show blank pages. There's always an error message. Once again: Learn PDO (and PHP).
  8. // 05:30 hours new DateInterval('P0000-00-00T05:30:00');
  9. Maybe a bit less Guinness can speed up the learning process.
  10. It's not the fault of PHP when you rather run in circles for hours than spend 5 minutes to RTFM. The DateTime class has less than 20 methods and is fully documented. How hard can it be to go through those methods and pick one that makes sense? I even told you the method you need to use (and guess how I found it: I read the manual). You're creating the problems yourself. The solution is right in front of you, but for some strange reason, you cannot see it until I put it into an extra-large font (which then pisses you off).
  11. You keep inventing methods and operators that just don't exist. And your error reporting is obviously misconfigured. The DateTime class doesn't have a "+" operator. It would be nice if it had, but there is no such feature. Read the manual. This tells you exactly what the class does and doesn't have. Hint: DateTime::add() looks promising.
  12. In your $donations loop, you're trying to pull data out of a $row variable, but $row only exists as a leftover from the previous query. It's the wrong variable. You need to use the acual key and value variables from this loop ($email, $images etc.). If you need more information about each donor, then adjust the data structure accordingly. $donations = []; foreach ($result_set as $row) { // if the donor doesn't exist yet, add their data if (!isset($donations[$row['width'].'x'.$row['height']][$row['email']])) $donations[$row['width'].'x'.$row['height']][$row['email']] = [ 'name' => $row['name'], 'url' => $row['url'], 'images' => [], ]; // append image $donations[$row['width'].'x'.$row['height']][$row['email']]['images'][] = $row['images_path']; } var_dump($donations); Don't just randomly combine code. Make sure you actually understand the context and what data is where.
  13. The DateInterval class doesn't have a sub() method. You need to either add the interval to $datetime1 or substract it from $datetime2. Then you can calculate the difference between the new limits.
  14. Dude. The syntax error isn't in line 12, it's in one of the lines before that. If you want help with a syntax problem, then we need to actually see the exact code, not an “and so on” placeholder. Is this really so hard to understand? Anyway, apparently you've repaired your secret code now. The new error is an interal library exception. Read the source code to understand why it's happening.
  15. The error is on line 12, you've posted two lines. How exactly are we supposed to figure out the rest? Mind reading?
  16. Then you still have other UNIQUE keys which shouldn't be there. MySQL doesn't just randomly overwrite data. If a record is overwritten, that's because one of your keys says it's a duplicate. No, because a view doesn't require any updates. It simply aggregates the data. The result can be cached by the query cache as long as the data doesn't change, so the calculation doesn't have to be repeated all the time. Frankly, it doesn't look like anybody in your team has actually though this through. A table is the worst option. It's the absolutely last resort when everything else has failed.
  17. I think you're missing the forest for the trees. The pseudo-code I posted is exactly what you need to write down in PHP – well, plus a few dollar signs and semicolons. $donations = []; foreach ($result_set as $row) $donations[$row['width'].'x'.$row['height']]['email'][] = ['name' => $row['name'], 'url' => $row['url']]; Yes, that's all. I'm sure you agree this is much, much simpler than the complex logic you currently have. Once you've built the array, you can iterate over the various groups with a nested foreach loop. foreach ($donations as $dimensions => $dim_donations) { // show heading with dimensions foreach ($dim_donations as $email => $images) { // show donor's name or email address // list images foreach ($images as $image) { } } }
  18. You don't need a table to aggregate data. There are views. I didn't say that at all. I said that the “primary key” you've chosen isn't a primary key, which means you need a different one. Like the combination of the extension and the date (assuming this does in fact identify the rows).
  19. Of course you have to HTML-escape the data you want to insert, not the entire markup.
  20. What exactly makes you think that HTML-escaping somehow doesn't work in this scenario? Because I don't see the problem here at all.
  21. I don't think you understand what a primary key is. The primary key is the unique identifier for the rows. If an extension can appear multiple times (on different dates), then it cannot be the primary key by definition. It may be important for various lookups, but it's definitely not a row identifier. The whole table doesn't make a lot of sense. When this is all just aggregated data from existing tables, why even have this extra table? Is it supposed to be some kind of cache to solve performance problems?
  22. Why does this matter? What's the problem if the user accesses the data?
  23. That function doesn't do anything. It creates a local array and then simply discards it, so the URLs cannot possibly be processed by cURL. Something is absolutely wrong here. Either you aren't showing me your real code. Or your description of how you get the wrong image size is nonsense. With the above code, you aren't getting any images. Last chance: Delete all old images, create a single download script, test it and post the real code here. No fantasy code.
×
×
  • 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.