-
Posts
1,718 -
Joined
-
Last visited
-
Days Won
55
Everything posted by maxxd
-
calendar stops displaying daily work shifts after midnight
maxxd replied to reverse_halo's topic in PHP Coding Help
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)... -
calendar stops displaying daily work shifts after midnight
maxxd replied to reverse_halo's topic in PHP Coding Help
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)? -
calendar stops displaying daily work shifts after midnight
maxxd replied to reverse_halo's topic in PHP Coding Help
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. -
calendar stops displaying daily work shifts after midnight
maxxd replied to reverse_halo's topic in PHP Coding Help
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. -
Anything other than simple class inheritance escapes me.
maxxd replied to KillGorack's topic in PHP Coding Help
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/ -
You also need to escape the slashes in your path.
-
Anything other than simple class inheritance escapes me.
maxxd replied to KillGorack's topic in PHP Coding Help
Sounds like you're looking at a facade pattern? Or maybe composite or adapter depending on how you want to use the objects. -
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.
-
Yeah, in CI it's a flash message - same general idea insofar as i recall.
-
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.
-
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.
-
Exporting Datatable data in Excel with a different Model function
maxxd replied to KSI's topic in PHP Coding Help
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. -
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.
-
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).
-
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\AplikasiInventaris\function.php on line 186 Fatal error: Uncaught TypeError: Unsupported operand types: int + string in C:\xampp\htdocs\AplikasiInventaris\function.php:186 St
maxxd replied to sandi123's topic in PHP Coding Help
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. -
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\AplikasiInventaris\function.php on line 186 Fatal error: Uncaught TypeError: Unsupported operand types: int + string in C:\xampp\htdocs\AplikasiInventaris\function.php:186 St
maxxd replied to sandi123's topic in PHP Coding Help
Is there a question here? -
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>';
-
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.
-
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).
-
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.
-
WP offers several sanitization functions - looks like you need sanitize_file_name().
-
Call to undefined method in included file
maxxd replied to richarddunnebsc's topic in PHP Coding Help
I agree with and you should heed both benananmen and gizmola's points. But for your specific question here looks - as ginerjm points to - like a question of scope. For instance, as you (I assume) learned fixing the database connection, you couldn't use $user or $pass variables within the __construct() method because you didn't pass those variables to the __construct() method. Every variable, method, and function (with some limited and typically ill-advised exceptions) has a scope outside of which it doesn't exist. So, look at where you define $data - is it in the same scope as where you use $data? Was it in the same function, or was it passed to the function that's trying to use it? -
That's kind of just a wall of poorly formatted code, so it's hard to tell where the actual problem is but let us see the GetPosts() method. What you're describing should be a data gathering concern, not a display concern. Other unsolicited advice - your entire comment output should be a method of it's own; right now the two blocks are almost identical. And I'm assuming the poor formatting is due to copy/paste issues, but on the off chance that it's not then fix that as it'll make reading your code much easier.
-
You can't make it work without altering the code you already have. Your code doesn't take pagination into account, so in order to use pagination you must alter your code. You'll need to add a LIMIT clause to your query, then add links that target the same page with an updated starting record ID. When your page is loaded, check to see if that start number is set - if it is, it becomes the new starting offset in your SQL limit clause. If it doesn't exist, the starting offset is 0. That should be enough to put you on the right path - give it a shot and if it doesn't work post your code here with your questions.