Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by mongoose00318

  1. See the entry on the bottom though? It's two entries with the same job number and same line item but a different description and quantity all together.
  2. Ugh...the way we store information in the AS400 is a nightmare. https://imgur.com/8gIpgg1 I have no real way to uniquely identify a job/line item...I'm trying to figure out a way to cross check the information in my database with what comes out of the AS400. I thought I could do that with the line item but see those orders in the screenshot? Order 23606661 has two line items of Q with completely different part numbers, qty, and description... Very cool tutorial. I look forward to doing it. Any ideas on how to cross check the info like I am trying to do? For example, today those orders could look like that but tomorrow a revision could have been done to one or more of those orders. I have other data tied to the order using it's id when I do the initial insert. I'm trying to post the revisions, archive the old info, and retain the ability to identify the order due to it's relationship with other data in the DB.
  3. @Barand Wow that's awesome. I'm going give it a try shortly. I've been doing the same thing with SQL as I have been with arrays. It's obvious to me that there are a lot of things I used to do years ago in PHP which I could have been handling with SQL statements themselves. I recently looked at some books on SQL on Amazon but didn't order one. Maybe I need to...often times when I'm looking online I don't find comprehensive examples. I'm sure they are out there but I just haven't come across them. One question I have about it: Is it just doing a mass update of the records in production_data? Here is what I programmed by the end of Friday: //loop through new orders array foreach ( $orders as $order ) { foreach ($result as $row) { //job already exists in DB if ( $order['job_number'] == $row['job_number'] && $order['line_item'] == $row['line_item'] ) { //check description field if ( $order['description'] != $row['description'] ) { //echo $order['job_number'] . ' : description is different. New: '. $order['description'] .' | Old: '. $row['description'] .'<br>'; } else { //echo $order['job_number'] . ' : description is same<br>'; } //check AS400 ship date if ( $order['scheduled_ship_date'] != $row['as400_ship_date'] ) { echo $order['scheduled_ship_date'] . ' : ship date is different. New: '. $order['scheduled_ship_date'] .' | Old: '. $row['as400_ship_date'] .'<br>'; } else { echo $order['scheduled_ship_date'] . ' : ship date is same New: '. $order['scheduled_ship_date'] .' | Old: '. $row['as400_ship_date'] .'<br>'; } $silly_count++; //job does not exist } else { //echo $row['as400_ship_date'].'<br>'; //echo $order['job_number'] . ' LN: ' . $order['line_item'] . ' has not match.<br>'; $silly_count++; } } $silly_count++; } I'm checking for two things before I archive/update a record; is the description or date from AS400 different than what is stored in MySQL. Then I use the archives to show the user past changes made to the order in the AS400. Sometimes those changes can be very small; like a dimensional change (ie 32 1/4" goes to 32 3/4"). So I built this to help the user more easily see changes to an order: https://imgur.com/yC4sNce Sorry I was more specific in my requirements. I look forward to trying this out and getting back to you with the results. Do you have any reading suggestions when it comes to learning how to better harness the power of SQL?
  4. @requinix Here is that code I mentioned earlier... //fetch production history data if( isset ( $action ) && $action == 'get_production_history' ) { $order_id = $_GET['order_id']; $production_history = []; $last_recorded = 0; $dept_codes = [5,6,7,8,10,11,12]; foreach ( $dept_codes as $d ) { $production_history[$d] = []; } //echo '<pre>'; //loop through depts foreach ( $dept_codes as $d ) { //loop through returned db rows foreach ( get_production_history( $order_id, $pdo ) as $row ) { if( $row['dept_code'] == $d ) { //set start time if ( !in_array ( $row[ 'id' ], $production_history[ $d ]) && $row[ 'status_id' ] === 1 ) { $production_history[$d][ $row['id'] ] = array( 'submit_time' => $row[ 'submit_time' ], 'finish_time' => '', ); //record id $last_recorded = $row['id']; //set finished time } elseif ( $row[ 'status_id' ] === 3 ) { $production_history[$d][ $last_recorded ]['finish_time'] = $row[ 'submit_time' ]; } } } } //find records without a finish time and unset them foreach ( $production_history as $dept => $value ) foreach ($value as $k => $v) if (empty($v['finish_time'])) unset($production_history[$dept][$k]); //find departments without records and unset them foreach ( $production_history as $dept => $value ) if (empty($value)) unset($production_history[$dept]); $json = []; $dept_arr_count = 0; //sort by dept foreach ( $production_history as $dept => $value ) { //get length of dept array $dept_arr_size = count($production_history[$dept]); //if on first entry for dept print parent if ( $dept_arr_count == 0 ) { //generate parent JSON entry $json[] = array( 'pID' => $dept, 'pName' => get_dept_name( $dept, $pdo ), 'pStart' => '', 'pEnd' => '', 'pClass' => 'ggroupblack', 'pLink' => '', 'pMile' => 0, 'pGroup' => 2, 'pParent' => 0, //need to set this for those that are children 'pOpen' => 1, 'pDepend' => '', 'pCaption' => '', 'pNotes' => '', ); } $submit_time = (isset($production_history[$dept][$k]['submit_time'])) ? $production_history[$dept][$k]['submit_time'] : ''; $finish_time = (isset($production_history[$dept][$k]['finish_time'])) ? $production_history[$dept][$k]['finish_time'] : ''; //print children foreach ($value as $k => $v) { $json[] = array( 'pID' => $dept .''. $dept_arr_count+1, 'pName' => '', 'pStart' => $production_history[$dept][$k]['submit_time'], 'pEnd' => $production_history[$dept][$k]['finish_time'], 'pClass' => 'ggroupblack', 'pLink' => '', 'pMile' => 0, 'pGroup' => 0, 'pParent' => $dept, //need to set this for those that are children 'pOpen' => 1, 'pDepend' => '', 'pCaption' => '', 'pNotes' => '', ); $dept_arr_count++; } //reached end of dept array if ( $dept_arr_size == $dept_arr_count ) { $dept_arr_count = 0; } } header('Content-type: text/javascript'); print(json_encode($json, JSON_PRETTY_PRINT)); } I was pretty proud of it haha. Here is what it generates... https://imgur.com/JW9Npz2
  5. Lol...just did a count on how many times that loop cycled through...I was off a bit from 40-50k.... It was more like 4,587,564.... Just a bit off...
  6. foreach ($result as $row) { if ( $order['job_number'] == $row['job_number'] && $order['line_item'] == $row['line_item'] ) { echo 'Found match on ' . $row['id'] . '<br><br>'; } else { echo $order['job_number'] . ' LN: ' . $order['line_item'] . ' has not match.<br>'; } } That loop does essentially what I was trying to do. It's just slow...looping through all records in the table for each record in the CSV. Okay, here is my table structure: -- -- Table structure for table `production_data` -- DROP TABLE IF EXISTS `production_data`; CREATE TABLE IF NOT EXISTS `production_data` ( `id` int(11) NOT NULL AUTO_INCREMENT, `job_number` int(8) NOT NULL, `enterprise` tinytext NOT NULL, `part_number` text NOT NULL, `description` text NOT NULL, `qty` int(11) NOT NULL, `line_item` varchar(11) NOT NULL, `as400_ship_date` date DEFAULT NULL, `hold_status` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; COMMIT; And here is a list of the columns I'm actually using from the CSV. It has other columns I'm not using though. //setup col vars for easier editing $enterprise = $column[2]; $part_num = $column[3]; $desc = $column[4]; $qty = $column[5]; $line_item = $column[6]; $job_num = $column[7]; $work_order = $column[8]; $psm = $column[9]; $date_change_flag = $column[10]; $scheduled_ship_date = $column[11]; $on_hold = $column[12]; $on_hold_reason = $column[13]; $total_hours = $column[14]; $worfc = $column[15]; After I find a match I'd like to compare certain fields in DB record against CSV row to see which ones have differences then make a backup of DB record and update the DB record with the new information from the CSV.
  7. Exactly what I'm trying to do. I've been learning about arrays and how much faster it is to do large complicated checks using them instead of hitting the database with repeated queries...which is why I'm trying to do it this way. If I wrote this with a query, it would probably result in 40,000-50,000 queries before it finished running...at least how I know to write it lol. So I did get the key from the matched array and the documentation mentions how array_search returns the key of it's first match. So on some matchs I am getting the wrong keys returned....maybe this is the wrong way to go about this... Basically, if the DB already has a job number and a line item which matches the new data; I want to check each field of that DB row against the new data to see if anything is different. If there is a difference I want to update those records and backup the old records in a different table. I am comparing a large CSV file against a table with almost 5,000 records.
  8. @Barand It's just a lot of values to compare against. I was trying to store all the rows of the particular table in an array and use the array to do the comparisons on; then when certain criteria is met, make an update on the specific record a match was found on.
  9. Hello, I'm trying to store the match I get in $result to a variable so that I can easily compare its other values against other values. Here is my code.. //loop through new orders array foreach ( $orders as $order ) { //compare job number and line item against database information for a match if ( array_search ( $order[ 'job_number' ], array_column ( $result, 'job_number' ) ) !== false && array_search ( $order[ 'line_item' ], array_column ( $result, 'line_item' ) ) !== false ) { $db_match = key($result); echo '<br><br>'.$db_match.'<br><br>'; echo 'Job: ' . $order['job_number'] . '/Line Item: ' . $order['line_item'] . ' was found<br>'; //new order which doesn't exist in database } else { echo 'Job: ' . $order['job_number'] . '/Line Item: ' . $order['line_item'] . ' was not found<br>'; } } When I do $db_match = key($result); I get 0 each time and when I do: $db_match = array_search ( $order[ 'job_number' ], array_column ( $result, 'job_number' ) ) !== false && array_search ( $order[ 'line_item' ], array_column ( $result, 'line_item' ) ) !== false; I get 1 each time...which I assume is the number of matches which meet that criteria instead of the array key I found a match on.
  10. I'll post some code later that I wrote yesterday building an array which is then passed as JSON to generate a Gannt chart on the fly. I'm proud of it for now...until you guys review it and tell me how repetitive my code is haha. It's cool learning to be more efficient with my code and really cool learning how to better build and interact with arrays. Back when I was still developing full time before I stepped away from it for several years; arrays was always something I had trouble with. I feel like I'm learning a lot about them now and it's making my life a lot easier.
  11. Okay very cool. Thanks a lot @requinix
  12. So $number is essentially being returned as an argument for the array_map() function?
  13. Also, what does the &$value do vs just $value in the below example? array_walk( $fruits, function( &$value, $key ) { $value = "$key is ".strtoupper($value); });
  14. I've seen this recently when looking at some PHP code and it feels very familiar because it's done in Javascript a lot. But, I don't have a good understanding of it even then...also, I'm not sure "inline functions" is the actual names of these...here is a sample... $cities = ['Berlin', 'KYIV', 'Amsterdam', 'Riga']; $aliases = array_map('strtolower', $cities); print_r($aliases); // ['berlin', 'kyiv, 'amsterdam', 'riga'] $numbers = [1, -2, 3, -4, 5]; $squares = array_map(function($number) { return $number ** 2; }, $numbers); print_r($squares); // [1, 4, 9, 16, 25] So where it says (array_map(function($number) {.... I'm confused about this part...normally when I write a function like... function($some_var) { return $some_var; } $some_var is acting as an input to the function...with the function sample above is $number acting as an output? $number has no value before the declaration of the function right? Hopefully I've worded this all correctly...
  15. I am checking the data coming in; here is my code for doing that and then setting the value's of the variables: //filters are set if(isset($_GET['filters'])){ //check field for manipulation $field = $_GET['filters'][0]['field']; if ( $field == 'Job Number' ) $field = 'job_number'; else if ( $field == 'Enterprise' ) $field = 'enterprise'; else exit(); //check type for manipulation $type = $_GET['filters'][0]['type']; if ( $type == '=' ) $type = '='; else if ( $type == 'like' ) $type = 'LIKE'; else exit(); //check value for job_number as numeric $value = $_GET['filters'][0]['value']; if ( $field == 'job_number' && trim( !is_numeric ( $value ) ) ) exit(); else if ( $type == 'LIKE' ) $value = "'%" . $value . "%'"; $filter_data = TRUE; }
  16. I'm trying to clean up all my functions with any queries which take dynamic parameters using PDO prepared statements. I originally thought I was using prepared statements and was told later I wasn't so it's been on my to-do list to go and clean them up. I have cleaned up a lot of them and tested them and they are working fine. This one is giving me a problem though.. /*fetch production data*/ if( isset( $field ) && isset( $type ) && isset( $value ) ) { $sql = 'SELECT id, job_number, enterprise, description, line_item, as400_ship_date FROM production_data WHERE :field :type :value ORDER BY enterprise, job_number, line_item LIMIT :offset, :records_per_page'; $stmt = $pdo->prepare($sql); $stmt->execute( [ 'field' => $field, 'type' => $type, 'value' => $value, 'offset' => $offset, 'records_per_page' => $records_per_page ] ); } else { $sql = 'SELECT id, job_number, enterprise, description, line_item, as400_ship_date FROM production_data ORDER BY enterprise, job_number, line_item LIMIT '. $offset . ', '. $records_per_page; } It takes values from some drop downs (I'm using tabulator to generate a table and this part is related to it's pagination functions)...here is the HTML for those elements. <div class="table-controls"> <div class="form-row"> <div class="col"> <label for="filter-field" class="col-form-label-sm">Field: </label> <select id="filter-field" class="form-control form-control-sm"> <option></option> <option value="Job Number">Job Number</option> <option value="Enterprise">Enterprise</option> </select> </div> <div class="col"> <label for="filter-type" class="col-form-label-sm">Type: </label> <select id="filter-type" class="form-control form-control-sm"> <option value="like" selected="selected">Like</option> <option value="=">Equal to</option> </select> </div> <div class="col"> <label for="filter-value" class="col-form-label-sm">Value: </label> <input id="filter-value" class="form-control form-control-sm" style="float: left;" type="text" placeholder="Value to filter..."> </div> <div class="col d-flex align-content-end flex-wrap"> <button id="filter-clear" class="btn btn-primary btn-sm rounded-0">Clear Filters & Sorting</button> </div> </div> </div> After attempting to put adjust the query to a prepared statement, I get the following error: Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? ? ORDER BY enterprise, job_number, line_item LIMIT ?, ?' at line 3 in C:\wamp64\www\test\scripts\order_status.php on line 125
  17. What do you think about this? $today = new DateTime("now"); $expected_complete_time = new DateTime($stat[ 'expected_complete_time' ]); $eta = $today->diff($expected_complete_time); $str_eta = $eta->format('%r%d'); if($expected_complete_time->format('d/m/Y') === $today->format('d/m/Y')) { $eta = 'Today'; } else { $eta = ($str_eta+1 == 1) ? $str_eta+1 . ' day' : $str_eta+1 . ' days'; } https://imgur.com/HTiuvrF Seems to be doing what I need.
  18. Also, it must be rounding or something? If I set the date for tomorrow; the difference I get is 0. If I put the expected date 2 days out; I get back a difference of 1. Maybe it's using the time in combination with date and not getting a whole day for the difference because of that? The date in the database doesn't have a time. It's just the date.
  19. Oops..yea that fixed it. But. I'm getting - and + on 0 values...? Can I just tell it not to do anything for a 0? https://imgur.com/a/Vn9RmFl Also, on this date... Now: 01/05/2020: Expected: 04/05/2020 Diff: +2 Shouldn't that say 3 days?
  20. I was trying to get something like: Now: 01/05/2020: Expected: 22/04/2020 Diff: -9 Now: 01/05/2020: Expected: 01/05/2020 Diff: 0 Now: 01/05/2020: Expected: 01/05/2020 Diff: 0 Now: 01/05/2020: Expected: 22/04/2020 Diff: -9 Now: 01/05/2020: Expected: 23/04/2020 Diff: -8 Now: 01/05/2020: Expected: 04/05/2020 Diff: +2 (but shouldn't this actually be +3?) Basically user says the amount of days it takes to complete some work and if today's date is passed that day then it shows a negative value.
  21. No matter the method I use I get positive dates when they should be negative? Here's changes to my code and the results... $today = new DateTime("now"); $expected_complete_time = new DateTime($stat[ 'expected_complete_time' ]); $eta = $expected_complete_time->diff($today); $str_eta = $eta->format('%R%d'); echo ': Now: ' . $today->format('d/m/Y') . ': Expected: ' . $expected_complete_time->format('d/m/Y') . ' Diff: ' . $str_eta; Now: 01/05/2020: Expected: 22/04/2020 Diff: +9 Now: 01/05/2020: Expected: 01/05/2020 Diff: +0 Now: 01/05/2020: Expected: 01/05/2020 Diff: +0 Now: 01/05/2020: Expected: 22/04/2020 Diff: +9 Now: 01/05/2020: Expected: 23/04/2020 Diff: +8 Now: 01/05/2020: Expected: 04/05/2020 Diff: -2
  22. I'm trying to subtract get the total number of days between two dates. I have been trying the DateTime date_diff method and the strtotime methods. I have it working mostly; but I have a problem with if the value should be negative. I've tried the invert() on the value that comes back from the date_diff() function but get errors. To sum up what I'm trying to do is: if ( $diff === 0 ) echo "Today" elseif ($diff > 0) echo "+" . $diff . "Days"; else echo "LATE -" . $diff . "Days"; Something like that. Here is my code... //retrieve expected complete time if ( isset( $stat[ 'expected_complete_time' ] ) ) { $today = new DateTime("now"); $expected_complete_time = new DateTime($stat[ 'expected_complete_time' ]); $today->setTime(12, 0, 0); $expected_complete_time->setTime(12, 0, 0); //calculate difference $eta = date_diff($expected_complete_time, $today)->format("%d");; //future if ($today > $expected_complete_time) { $eta = '+' . $eta; //today } elseif ($eta === '0') { $eta = 'Today'; //overdue } else { $eta = 'LATE:-' . $eta; } } else $eta = '';
  23. Awesome. Thanks for the clarity & insight! I will look into it some more.
  24. Well sort of...I mean does it inherit the object assigned to $(this) from the outside code unless you redefine it later and can you redefine the object assigned to $(this)? Did I phrase that right?
  25. Can I still this $(this) if I remove the second argument?
  • 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.