get_results( $query, ARRAY_A ); $i = 0; foreach ( $rows as $row ) { $et = get_entry_type( $row['entry_type'] ); if ( 'y' == $et['hasBacking'] ) { $bt = get_backing_type( $row['backing_type'] ); $price = $prices['price'][$et['ID']][$bt['ID']]; } else { $bt = false; $price = $prices['price'][$et['ID']]; } $new_row = [ 'ID' => $row['ID'], 'added' => $row['added'], 'price' => $price, 'entry_type_ID' => $et['ID'], 'entry_type' => $row['entry_type'], 'backing_type_ID' => ( ! $bt ) ? null : $bt['ID'], 'backing_type' => ( ! $row['backing_type'] || '-' == $row['backing_type'] ) ? null : $row['backing_type'], 'prefix' => $row['prefix'], 'first_name' => $row['first_name'], 'last_name' => $row['last_name'], 'street' => $row['street'], 'zip' => $row['zip'], 'city' => $row['city'], 'email' => $row['email'], 'phone' => $row['phone'], 'email_subscription' => $row['email_subscription'], 'agree' => 'n', ]; $wpdb->insert( $new_table, $new_row); $submission_ID = $wpdb->insert_id; if ( ! empty( $row['partners'] ) ) { $partner_discount = $prices['per_partner_discount']; $total = $price; $p = unserialize( $row['partners'] ); foreach ( $p as $title ) { $discount = bcdiv( bcmul( $price, $partner_discount ), 100, 2 ); if ( 1 == bccomp( $discount, $total, 2 ) ) { $discount = $total; } $total = bcsub( $total, $discount, 2 ); if ( -1 == bccomp( $total, '0', 2 ) ) { $total = '0'; } $new_partner = [ 'submission_ID' => $submission_ID, 'title' => $title, 'discount' => $discount, ]; $wpdb->insert( "{$new_table}_partner", $new_partner); } } echo ++$i, ' '; flush(); ob_flush(); } // ----------------------------------- function get_entry_type( $title ) { global $entry_types_en, $entry_types_de; if ( array_key_exists( $title, $entry_types_de ) ) { return $entry_types_de[$title]; } if ( array_key_exists( $title, $entry_types_en ) ) { return $entry_types_en[$title]; } return false; } function get_backing_type( $title ) { global $backing_types_de, $backing_types_en; if ( array_key_exists( $title, $backing_types_de ) ) { return $backing_types_de[$title]; } if ( array_key_exists( $title, $backing_types_en ) ) { return $backing_types_en[$title]; } return false; }