Jump to content

maxxd

Gurus
  • Posts

    1,698
  • Joined

  • Last visited

  • Days Won

    53

Everything posted by maxxd

  1. I'm glad to know Mustache.php is still active - it's the first template system I used in php. Right now I'm using mostly Laravel so I'm on Blade, but before that I was using Twig, which is syntactically very similar and just kinda awesome.
  2. Doing my digging and it appears this is chapter 4. Code from the sample: <?php Require_once("e10dog.php"); $lab = new Dog; // ------------------------------Set Properties-------------------------- $dog_error_message = $lab->set_dog_name('Fred'); print $dog_error_message == TRUE ? 'Name update successful<br/>' : 'Name update not successful<br/>'; Note the lack of 'bool' before $dog_error_message. I'm not trying to be a jackass here, but when you're learning a language you have to read the tutorials completely, follow them accurately, and listen to the people who know what they're talking about when they try to help with any confusion.
  3. lab.php does not define a class. It uses a class - these are two very different things. Look at my previous examples and the use of the word 'class'. Then compare that to your own files; I think you'll see the important difference. I don't have Learn PHP 8 from apress, but the source is available through github. What chapter is this lesson?
  4. Right. And I see where you instantiate an instance of that class in the global namespace, right before you try to type a variable in that same global namespace. The code you're showing isn't inside a class or a method/function signature. For instance, <?php class Testing{ private bool $truefalse; } is perfectly valid, because it's inside a class. <?php function testing(bool $truefalse){ echo $truefalse; } is also perfectly valid as that's typing a function parameter. However, <?php bool $truefalse = false; is not valid, as it's not within a class or function.
  5. But in the code you've posted, you don't have a class. You can type method/function parameters and class properties, but as far as I've found trying to type variables in the global namespace doesn't work even in 8.0. What book are you using?
  6. All that having been said, understand that any time span type calculation is ... just harder than it should be. You look at it and it's like "oh, yeah - no problem". Then you start actually working on it and it's far more complicated than you might think. So even the idea of comparing not only start time and end time as implied above, you suddenly then have to consider potentially time zones and then daylight savings time (which is it's own barrel of fish)...
  7. Where you assign $day_end_each, you've got several (frankly, redundant) calls to date() to define the month, day, and year. Replace those calls with specified values and you can set any date you'd like. However, I have a sneaking suspicion that the problem may lie with the direction of your comparison. It seems like your query is working when considered from the start of the shift, but there's no consideration for the end of the shift. So perhaps there needs to be a condition that looks at $row['shift_'.$i.'_end'] or $row['shift_'.$i.'_start'] + $shift_duration (or something similar)?
  8. I would start off by using var_export to dump the result of each of your conditionals. echo "<pre>".var_export(date("Y-m-d", strtotime($row["shift_" . $i . "_start"])) == date("Y-m-d", strtotime($date_each)), true)."</pre>"; echo "<pre>".var_export(date("Y-m-d H:i:s", strtotime($row["shift_" . $i . "_start"])) <= $day_end_each, true)."</pre>"; echo "<pre>".var_export($row["member_shift_" . $i . "_on_call"] == 0, true)."</pre>"; From there you can check if and where your logic chain is failing, and that'll give you a more specific place to start actually debugging.
  9. You've got three conditionals happening in your if statement - do you know that $day_end_each is the part that's failing? Print out each of your conditionals and make sure you're focusing on the right one. Having no idea what $row['shift_{$x}_(start|end|on_call)'] actually contains, there are several ways the comparisons may have gone wrong.
  10. Highly recommend this book if you're getting into patterns and more advanced OO concepts: https://www.amazon.com/PHP-Objects-Patterns-Practice-Enhancements/dp/1484267907/
  11. You also need to escape the slashes in your path.
  12. Sounds like you're looking at a facade pattern? Or maybe composite or adapter depending on how you want to use the objects.
  13. To clarify, it's standard practice to omit the closing tag in files that only include PHP. If you're mixing your PHP into HTML (which is it's own kettle of fish) you can either close the PHP block before you write your HTML or - as ginerjm mentioned - you can use a heredoc and then output the markup from that variable.
  14. Yeah, in CI it's a flash message - same general idea insofar as i recall.
  15. This is typically called a toast notification. For instance, if you happen to use Laravel you'd install toastr as a dependency in pacakge.json: "dependencies": { "toastr": "^2.1.4" } Create a toast component or partial: <script> @if(Session::has('message')) window.toastr.success("{{ session('message') }}"); @endif @if(Session::has('error')) window.toastr.error("{{ session('error') }}"); @endif @if(Session::has('info')) toastr.info("{{ session('info') }}"); @endif @if(Session::has('warning')) window.toastr.warning("{{ session('warning') }}"); @endif </script> Include that component/partial in your main template file: @include('components.toast') Finally, set the message in $_SESSION like so: return Response::redirect('/dashboard')->with('message', 'Data Saved!'); Obviously if you're not using Laravel you'll have to do some digging but hopefully that's a decent starting point.
  16. Sounds like you want a Markdown library. I can't say for sure as I think I'm the one person on the planet that's not used Reddit, but `>` denotes a blockquote in most Markdown versions I've come across. If you Google it, there are many PHP libraries that can help you out.
  17. Give the documentation, it looks like the functionality you want is the default. I've not used DataTables but I'd start by removing the `columns: ':visible'` from your exportOptions object; the pages aren't visible so that may have something to do with it.
  18. I'm a huge fan of soft-delete, personally. IMO the only time data should be completely and actually deleted is in the case of a GDPR request or some other situation where you can face legal action for not deleting the information completely. I've even seen setups where the user's data is replaced by basically a hash - the record still exists, any foreign records still exist and link back to the original record, but the personal data has been scrambled or blinded in some way that makes it basically useless to anyone who can view it.
  19. In addition to the above, I find PHP DocBlocker, Better Comments, Auto Close Tag, and Auto Rename Tag pretty necessary to my setups. There's a number of format and syntax plugins that I use for other languages but I would hate working in VSCode without these and Intellephense (just make sure you follow gizmola's advice).
  20. First and foremost, I hope this code isn't on a live server - you're wide open to SQL injection in many, many places. That having been said, there's also some suspect logic - for instance, line 186. Even if it were working I'm not sure you'd be getting the results you expect. Right before that, you set $stok_awal to the value of $data['qty'] or 0 if $data['qty'] is null. You then subtract $data['qty'] from $stok_awal (which again, is the value of $data['qty'] or 0) without checking to make sure that $data['qty'] exists. The basic problem here is that $data['qty'] doesn't exist. Or more to the point, $data is null. You need to output $data and see what exactly - if anything - it contains. After that, look into prepared statements and update all your queries.
  21. What error did you notice in your index.php file? Assuming the 'It has this in it,' is a copy/paste error and not actually in that php file, it looks fine (best practice is to leave off the closing php tag, but I don't think that has any bearing on your current issue). Please excuse me if this is a dumb question, but your comment about the error in Apache's log and mac_guyver's excellent point about the OS injecting file extensions got me thinking a couple things. You've tested that Apache itself is working, yeah? Like, you get the welcome page on a fresh site setup? Also, the page you're trying to serve via Apache has a '.php' extension? If you put the following code into the file 'testing.php' and the visit 'http://{yourdomain}/testing.php' you see 'Hello World!', right? <?php echo '<p>Hello World!</p>';
  22. OK, if there's no `mysqli` section in the output from phpinfo() then it's not enabled. Check your C:\PHP8\php.ini file and make sure the line `extension=mysqli.dll` doesn't have a semi-colon in front of it. Restart IIS and if that doesn't do it, then I'm sorry but somebody with more hands-on experience than I is gonna have to step in.
  23. I haven't run PHP on windows in literally a decade or longer, so I'm not sure how much help I'm going to be. Do you have a section labeled 'mysqli` in the output from `phpinfo()`? You mention in your first post that you've updated C:\PHP8\ext, but your phpinfo is showing the config as C:\PHP8\php.ini - I know in Ubuntu there's an entire folder full of extension files - mine is at `/etc/php/8.0/mods-available` and includes files like `mysqli.ini`. As a bit of an aside, is this for production or development? If you're looking at a development setup on a windows machine I highly recommend either using WSL or Docker - preferably Docker, but it's not always an option (I'm typing this on my Surface tablet that can't handle Docker so I use local installs in WSL for dev).
  24. Definitely check phpinfo() as mac_guyer recommended. Sometimes PHP uses an unexpected configuration file - check for both the Loaded Configuration File value and make sure that there's a full mysqli section in the output. Also, save yourself a ton of pain and switch to PDO now - it's much easier to deal with than mysqli overall.
×
×
  • 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.