-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Try it and find out. In the hour+ since you posted this thread, you could have installed MySQL Workbench, set it up, and started using it.
-
alert message every length increase of 5
requinix replied to StevenOliver's topic in Javascript Help
And all the other on*s, yes. The reasons to avoid them are too complicated and lengthy for me to want to go into now (Google is your friend), but the highlights are: 1. It's a good thing to keep HTML and Javascript separate from each other 2. Using onclick attributes means you can only have the one click event handler 3. Managing event handlers that way is annoying when you start getting into larger applications Establish the right habits now and you won't have to reconsider what you're doing later. -
if( isset ( $action ) && $action == 'get_production_history' ) { Where is $action being defined? If it's coming from $_GET/POST then that is where the isset() should be. Because the point of using it is to make sure it really does exist (or else PHP will complain that it does not). But once you've assigned something to a variable, it definitely does exist (even if the thing you were assigning to it did not), so the isset() is probably unnecessary. foreach ( $dept_codes as $d ) { //loop through returned db rows foreach ( get_production_history( $order_id, $pdo ) as $row ) { get_production_history() does a database query, right? Given that you aren't passing it any department information, won't this run the exact same query over and over again? If that is the case then you should switch these two foreachs around so that the database one only happens once while the department one (which just goes over a small array) happens more than once. if( $row['dept_code'] == $d ) { If you only care about production history data matching a specific department then running a query for everything is highly wasteful. This problem partly goes away if you do the thing I said above, but better would be to find a way to run a modified query for production data that only includes results for the departments you want. if ( !in_array ( $row[ 'id' ], $production_history[ $d ]) && $row[ 'status_id' ] === 1 ) { Does this mean that the query will somehow be returning multiple rows with the same ID and dept_code for status_id=1? That doesn't sound good. } elseif ( $row[ 'status_id' ] === 3 ) { How do you know that this $row corresponds to the earlier $last_recorded row? Wouldn't it just be easier to forget $last_recorded and use $row's ID in here? foreach ( $dept_codes as $d ) {... foreach ( get_production_history( $order_id, $pdo ) as $row ) {... // assuming you rearrange these two loops like I said foreach ( $dept_codes as $d ) {.... foreach ( $production_history as $dept => $value )... foreach ($value as $k => $v)... foreach ( $production_history as $dept => $value )... foreach ( $production_history as $dept => $value ) {... foreach ($value as $k => $v) {... That's a lot of loops over the same data. You should be able to combine some of these. Tip: use a continue to skip the rest of the code in a looped block. header('Content-type: text/javascript'); text/javascript means Javascript, and while you are outputting valid Javascript, that's not what you're trying to do. JSON is "application/json".
-
alert message every length increase of 5
requinix replied to StevenOliver's topic in Javascript Help
1. It's bad practice to create global variables. 2. It's also bad practice to write inline event handlers. 3. Your message says "at least 5" but your code checks for more than five. <textarea id="something"></textarea> <script> (function() { var character_count = 5; var multiples = 1; var textarea = document.getElementById("something"); textarea.addEventListener("input", function() { if (textarea.value.length >= (character_count * multiples)) { alert("At least 5 more characters were entered."); multiples++; } }); })(); </script> 1. Wrapping all your stuff in an anonymous function that executes immediately will keep the variables safe. 2. Use addEventListener to attach events dynamically. -
alert message every length increase of 5
requinix replied to StevenOliver's topic in Javascript Help
Every time this function runs, incrmt - which you really should spell out normally - will be set to 5. Every time. The variable needs to come from outside the function so there's only one copy of it floating around. -
Your terminology is incorrect (an "argument" is something passed to a function when it's called) but yes: the function returns a new value which array_map uses in the new array it's creating.
-
Just about everyone will recognize what you're describing with that name, but they're officially called "closures" or "anonymous functions". It's a function like any other. It takes an argument of $number and returns something. There's nothing particularly special about how it works. The & indicates a reference. array_walk has a special behavior where you can modify the value in the array - but instead of returning the new value, you mark the first argument in your function as being by-reference and modify it directly.
-
So Stackoverflow banned Col Shrapnel/ of Phpdelusions
requinix replied to gizmola's topic in Miscellaneous
People still use StackOverflow? That's only half a joke. Their community has always been toxic to newcomers and there's so much emphasis on correctness that anything less than perfect is unacceptable. And there's the hostility towards any form of discussion about what is right that I always mention when this subject comes up. SO is good when you're looking for a precise answer to a specific question, but it's terrible for actually asking the questions, or trying to weigh in as a new person with different answers. But I am glad they dethroned Expert Sex Change in search results. edit: If Your Common Sense/shrapnelcol came across this thread and decided they wanted to join our forum...- 1 reply
-
- 4
-
What you need to do is go back to that SUM/COUNT thing you tried. Because that is, in fact, the right way to go here. Probably. What was that query and what do you mean by "it didn't work"?
-
Selecting records without relations in another table
requinix replied to Strahan's topic in MySQL Help
Now there's an avatar I haven't seen in a while. Conditions in an ON are about deciding how stuff in the two tables relate to each other, while conditions in the WHERE are about filtering what you want to see in the results. That's probably not the best way to explain it... Here you're dealing with readlog.uid. Normally stuff in an ON is for fields in both tables that equal each other, but remember: it's about relationships here. And what that uid really means to the query is "chapters that are not in someone's readlog". In effect, checking the uid is half of the work (the "someone's readlog" part) and the OUTER JOIN + dateread is the other half (the "chapters that are not in" part). Of course, the fact that the second half is being done in outside an ON and actually inside a WHERE is just an unfortunate result of the SQL syntax... Ah, I'm tired. That probably didn't make any sense and I'm sure someone else could do better. -
Prevent Arrays With preg_match() function
requinix replied to mojobadshah's topic in PHP Coding Help
What? The code you posted will take sample.txt, read what's in it, add to that another copy of what's in it but with the regex run on it, then dump that all back to sample.txt. So if you run the code multiple times then the files goes like a -> ab -> abbb -> abbbbbbb -> abbbbbbbbbbbbbbb... -
Fatal error: Allowed memory size of bytes exhausted
requinix replied to TrueMember's topic in PHP Coding Help
If you tried increasing the memory limit and the memory limit didn't increase then you didn't increase the memory limit. You did you edit the correct file? Restart PHP or your web server? -
You might as well do it for all your classes, not just this "libraries" folder. As an example of how to do autoloading, I would point you to the place in your code where you are (apparently) already doing autoloading.
-
You can make whatever changes you'd like - as long as that User.php file gets included before you try to use the class. Or better yet, learn about and implementing autoloading so you never have to care about including files manually.
-
I wasn't asking what the code does. I meant you. The human being. So how would you decide what shift was correct? Perhaps it's like kicken suggested and you only think about when they clocked in?
-
How do you maintain which shift they were on? If you had to decide, how would you do it?
-
If you're talking about it getting the user currently browsing the site, also look into what it takes to set up Kerberos authentication on your web server. Because that's not something PHP can handle for you - at least not without help.
-
Ajax: "jquery style" vs "Microsoft XMLHTTP style"
requinix replied to StevenOliver's topic in PHP Coding Help
Let me put it this way: // code for IE6, IE5 Do you care about IE6? -
That would be because CSS is for HTML. PDFs do not support CSS. TCPDF does not do CSS as far as I can tell. So either you forget CSS and tell TCPDF explicitly what styling you want to use everywhere, or you pick another HTML-to-PDF library that does support CSS. If I can remember what library I used some time ago and was fairly pleased with then I'll mention it.
-
You're barking up the wrong tree. In the first version PHP is telling you that it doesn't know what that User class is. I see in the second version you're require_once()ing a file before trying to use its class...
-
Ajax: "jquery style" vs "Microsoft XMLHTTP style"
requinix replied to StevenOliver's topic in PHP Coding Help
1. XMLHttpRequest is supported everywhere now. There is no reason for any modern application to even know about Microsoft.XMLHTTP. 2. jQuery does all this decision making for you. So what do you think? -
If echo is '12:00 pm' then display '12:00 noon' instead
requinix replied to Ichibanj's topic in PHP Coding Help
I assume you're talking about the language barrier and people not knowing what "PM" means? But if that's the case then I wouldn't expect them to know what the word "noon" means either. As you've seen, neither PHP nor WordPress have something to print the time in the format you want. So you'll have to write some code to do it. Have you tried that yet? What did you come up with and how was it not working? -
Not exactly. You should be able to answer the question on your own now.