Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/14/2023 in all areas

  1. There is a slight error in the second foreach loop where you check for extra SKUs. You are comparing the received count with the expected count, but you should be checking if the received count is greater than the expected count. Try replacing the second foreach statement with this: foreach ($received_counts as $sku => $received_count) { if (!isset($expected_counts[$sku])) { $extra = array_merge($extra, array_fill(0, $received_count, $sku)); } elseif ($received_count > $expected_counts[$sku]) { $extra = array_merge($extra, array_fill(0, $received_count - $expected_counts[$sku], $sku)); } }
    1 point
  2. I'd do it like this... ################################################################################ # CREATE TEMPORARY STAGING TABLE # ################################################################################ $pdo->exec("CREATE TEMPORARY TABLE tempdata ( id int not null auto_increment primary key, sales_doc_type varchar(10), billing_date date, material varchar(10), gross_amount int, sales_office varchar(10), plant varchar(10) ) "); ################################################################################ # READ CSV, # # EXTRACT REQUIRED DATA, # # STORE IN ARRAY FOR INSERTION TO TEMP STAGING TABLE # ################################################################################ $fp = fopen('test1.csv', 'r'); $req_cols = [ 0 => 'sales_doc_type', 2 => 'billing_date', 11 => 'material', 25 => 'gross_amount', 45 => 'sales_office', 47 => 'plant' ]; $import_data = []; while ($allrow = fgetcsv($fp)) { $row = array_intersect_key($allrow, $req_cols); $randdays = rand(5,30); $row[2] = date('Y-m-d', strtotime($row[2])); $row[25] = str_replace(',', '', $row[25]); $import_data[] = vsprintf("('%s','%s','%s','%s','%s','%s')", $row); } fclose($fp); ################################################################################ # ADD RECS FROM ARRAY TO TEMP TABLE - 2000 AT A TIME # ################################################################################ $chunks = array_chunk($import_data, 2000); foreach ($chunks as $ch) { $sql = "INSERT INTO tempdata (sales_doc_type, billing_date, material, gross_amount, sales_office, plant) VALUES " . join(',', $ch); $pdo->exec($sql); } ###################################################################################################################### # # # Now we have the data from the csv stored in a temporary staging table # # which makes it easy to manipulate the data with queries to update our # # database tables with efficient queries rather than running multiple # # queries inside loops. # # # # NOTE - as I never received a reply to my question about the origin of the # # data used toupdate the members table I have had to omit that part # # of the processing. The UPDATE query will be similar to the INSERT # # below except it will update where there is a matching record # # # ###################################################################################################################### ################################################################################ # INSERT TEMPDATA REC INTO billing WHERE NO MATCHING billing_date IN members # ################################################################################ $pdo->exec("INSERT INTO billing (sales_doc_type, billing_date, gross_amount, sales_office, plant, material) SELECT t.sales_doc_type , t.billing_date , t.gross_amount , t.sales_office , t.plant , t.material FROM tempdata t LEFT JOIN members m ON DATE(t.billing_date) = m.billing_date WHERE m.billing_date IS NULL ");
    1 point
  3. code $data = file('data.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); usort($data, fn($a, $b)=>substr($a,11,2)<=>substr($b,11,2)); // sort by code number $codes = []; foreach ($data as $d) { $p = strpos($d, ')'); $k = substr($d, 11, $p-10); if (!isset($codes[$k])) { $codes[$k] = 1; } else { $codes[$k]++; } } echo (join("<br>", $data)); echo ("<h3>Total clicks</h3>"); foreach ($codes as $code => $total) { printf("%s Total clicks = %d<br>", $code, $total); } output 15/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Finland Helsinki Uusimaa 18/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Finland Helsinki Uusimaa 21/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Germany Gera Thuringia 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Edmore Michigan 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Alhaurin de la Torre Malaga 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Alhaurin de la Torre Malaga 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Madrid Madrid 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Nerja Malaga 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Cartagena Murcia 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 21/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Nerja Malaga 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Garden City New York 21/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 Norway Sira Agder 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 Spain Muro del Alcoy Alicante 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Edmore Michigan 10/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 11/09/2023 20 The Legacy of Jesus (El Legado de Jesús)20-8-2023.mp3 United States Ashburn Virginia 15/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Finland Helsinki Uusimaa 18/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Finland Helsinki Uusimaa 21/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Germany Gera Thuringia Total clicks 03 Resist the Curse (Resiste la Maldición) Total clicks = 3 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) Total clicks = 19 05 Day of Atonement 2023 (Día de la Expiación) Total clicks = 12 19 The Bread of Life (El Pan de la Vida) Total clicks = 11 20 The Legacy of Jesus (El Legado de Jesús) Total clicks = 1 20 Be With Me Where I Am (Está Conmigo Donde Estoy) Total clicks = 3
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • 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.