-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Trying to compress and make my code faster
requinix replied to mongoose00318's topic in PHP Coding Help
Here's the structure of how your queries are run: foreach "SELECT * FROM production_data ORDER BY enterprise, job_number, TRIM(line_item) ASC" { $status_qc = "SELECT <status_id> FROM production_status WHERE order_id = <production_data.id> AND dept_code = <10> ORDER BY submit_time DESC LIMIT 1"; $status_thermoforming = "SELECT <status_id> FROM production_status WHERE order_id = <production_data.id> AND dept_code = <6> ORDER BY submit_time DESC LIMIT 1"; $status_vinylpaint = "SELECT <status_id> FROM production_status WHERE order_id = <production_data.id> AND dept_code = <5> ORDER BY submit_time DESC LIMIT 1"; $status_finalassm = "SELECT <status_id> FROM production_status WHERE order_id = <production_data.id> AND dept_code = <7> ORDER BY submit_time DESC LIMIT 1"; $status_crateship = "SELECT <status_id> FROM production_status WHERE order_id = <production_data.id> AND dept_code = <8> ORDER BY submit_time DESC LIMIT 1"; } There are two complications in here: the fact that your departments are dynamic but your code cares about five specific ones, and that you want the most recent record for an order per department. This means that while all six of these queries could be combined into one, you'd end up with one query that uses 10 joins. That sucks. So I think I would settle for two queries: getting everything you want from production_data, but before that getting the most recent status per department for all orders. With some quick preprocessing on that you could look up each status very quickly. SELECT p1.order_id, p1.dept_code, p1.status_id FROM production_status p1 LEFT JOIN production_status p2 ON -- find similar records p1.order_id = p2.order_id AND -- ...for the same order p1.dept_code = p2.dept_code AND -- ...and the same department p2.submit_time > p1.submit_time -- ...and that come after the row that p1 found WHERE p1.dept_code IN (5, 6, 7, 8, 10) AND -- limit to department we care about p2.id IS NULL -- filter to keep only the p1 rows that didn't have later p2 rows $statuses = []; // foreach $row from that query { if (!isset($statuses[$row["order_id"]])) { $statuses[$row["order_id"]] = []; } $statuses[$row["order_id"]][$row["dept_code"]] = $row["status_id"]; // } -
I could write a huge reply, but it'll be easier for me to just point you to MDN.
-
Trying to compress and make my code faster
requinix replied to mongoose00318's topic in PHP Coding Help
Almost certainly. What's the code for those functions? -
Trying to compress and make my code faster
requinix replied to mongoose00318's topic in PHP Coding Help
The source of the slowness is going to be database queries - nested switches won't be much of a problem (as far as the PHP engine is concerned). I'm concerned about all those get_user_dept and get_order_status calls. Do they do database queries? About cleaning up the code, I'm sorry but that's way too much for me personally to bother with. My advice is to improve it one step at a time: find out the differences between each switch case, pull them out into something more manageable (like an array), and build your HTML using data from it. For example, the $user_dept_code=4/9 > $status_qc switch has all the buttons looking the same except for a CSS class or two and the inner text. Take those differences out into an array like [ 1 => ["btn-warning", "In Progress"], 2 => ["btn-danger", "Delayed"], 3 => ["btn-success", "Finished"], ... ] You can look up the CSS class and text using $status_qc. You may also discover that you messed up some of the markup. And please, do yourself a favor and create your own CSS classes. All those inline styles are bad. -
Not with the way your code is written, no. I trust you're familiar with prototyping? Employee and SalesPerson both set up their methods through assignment. It works, but it's not modern Javascript. Using prototyping the code would be function Employee(foo) { this.foo = foo; this.name = ''; this.dept = 'general'; } Employee.prototype.method1 = function() { console.log('method1: ' + this.foo); } Now see what happens with and without those two lines. Using a prototype gives you "inheritance" without any additional work. There's one copy of the method2 function around and everybody uses it. With the older style, every single instance has its own separate method2.
-
Need url parameter "read" so it gets embedded into a buy-link
requinix replied to mac007's topic in Javascript Help
But apparently you didn't read the second sentence on the page. -
That is an IP address. It's called IPv6.
-
Need url parameter "read" so it gets embedded into a buy-link
requinix replied to mac007's topic in Javascript Help
MDN has something useful. -
Well, if you're just doing this for yourself then by all means, go ahead and experiment around with it. Rewrite what? PDO is one of the best database APIs available...
-
Either https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_datediff or https://www.php.net/manual/en/class.datetime.php
-
Do you actually have an "S_POST" array?
-
Apparently the author of whatever PHP language server extension you're using decided that their list would show deprecated items and give you the choice of whether you used them. If you don't like that, see if there's a setting to hide them.
-
Here's part of a regular expression-based find and replace for you: function capitalizeWords(str) { return str.replace(/(^|[\s.-])([a-z])/g, function(???) { return ???; }); } It checks for all letters at the beginning of the string, or after spaces, periods, or hyphens, then gives each result to a function. Your tasks are to: 1. Fill in the arguments. The first argument is the whole thing matched, the second is the space or period or whatever that was matched before the letter, and the third is the letter to capitalize. 2. Return the string to replace at that position. Note that it will replace the entire string matched, not just the letter.
-
Trying to Send credentials to an IP camera
requinix replied to AndyLasers's topic in PHP Coding Help
Digest authentication is rather complicated. Do you have any way to change the authentication system it wants to use? Perhaps to "Basic"? -
Exactly my point.
-
Look carefully at the condition for your first rewrite. Have one redirect that does just the extension and one that does just the slash. (And in that order.) Don't try to do half of both at the same time.
-
So every time you log out, clear your browser cookies, blah blah blah, and log back in, you get the same token? Every time? And when you log in using PHP code they give you the same token as well?
-
Then that could be it. They're tracking client IP address with the token, and the token is not valid when used from another location. You'd have to generate the token from within PHP. Can't just copy and paste what your browser is doing.
-
Are you running PHP locally? That's the only thing I can think of.
-
At the moment the only thing I can guess is that you're updating all messages in a thread when you should be updating individual messages.
-
It seems right. Is there any more information you can get from the remote service? More detailed error message? An error log? Any logs at all?
-
Not unless you're a high-traffic site. You can't run PHP code unless something triggers it, and relying on people hitting your website isn't safe. If you need to run some code at a particular time then cron, or scheduled tasks on Windows, are the correct answer.
-
$tools is not a collection of tools. It is an associative array containing 2 or 4 values. foreaching over an associative array is almost always incorrect. if (isset($tools["good_quality"])) { printf("We have %s good quality tools at $%.02f each", $tools["good_quality"], $tools["good_price"]); } if (isset($tools["broken"])) { printf("We have %s broken tools at $%.02f each", $tools["broken"], $tools["broken_price"]); }