Chciałem zrobić porównanie produktów z dwóch sklepów. Szukam produktów po kodzie produktów. Jeżeli jest podobny to porównuje liczbę produktów. Problem polega na tym że jak print poszczególne zmienne to wyniki sa raczej poprawne. Jednakże jak wyświetla zawartośc tablicy to wartości są dziwne. Na pierwszy rzut oka są powielone....
Cały kod:
$conn1->close(); $conn2->close(); foreach ($result_source AS $source) { $found = false; foreach ($result_target AS $target) { if ($code_source === $code_target) { if ($source['quantity'] !== $target['quantity']) { $match[] = array('code' => $source['code'], 'quantity' => $source['quantity'], 'targetid' => $target['id'], 'sourceid' => $source['id']); } $found = true; break; } } if (!$found) { $new[] = array('code' => $source['code'], 'quantity' => $source['quantity'], 'sourceid' => $source['id']); } } $msg = ''; foreach ($match AS $entry) { $msg .= 'Change identified: Home_ID=' . $entry['sourceid'] . ' code: ' . $entry['code'] . ' quantity:' . $entry['quantity'] . PHP_EOL . '<br />'; #print $msg; } foreach ($new AS $entry) { $msg .= 'New Entry: Home_ID=' . $entry['sourceid'] . ' code: ' . $entry['code'] . ' quantity:' . $entry['quantity'] . PHP_EOL . '<br />'; #print $msg; }
Wynik dla
Znajduje się pod adresem: http://suszek.info/projekt1/
Jeżeli wyświetlę
foreach ($match AS $entry) { $msg .= 'Change identified: Home_ID=' . $entry['sourceid'] . ' code: ' . $entry['code'] . ' quantity:' . $entry['quantity'] . PHP_EOL . '<br />'; }
Wynik znajduje się pod adresem: http://suszek.info/projekt1/index_1.php
Wydaje mi się że źle dodaje elementy do tablicy $match stąd jest aż tyle wpisów.
Z góry dzięki za pomoc.
Pozdrawiam
----edycja
Pomimo instrukcji warunkowych skrypt tworzy mi puste tablice: http://suszek.info/projekt1/index_1_1.php
if ($code_source === $code_target) { if ($source['quantity'] != $target['quantity']) { $test[] = array('code_source' => $source['code'], 'quantity_source' => $source['quantity'], 'targetid' => $target['id'], 'sourceid' => $source['id'], 'targetcode' => $target['code']); }
Wydaje mi się że tutaj jest problem. Jest ktoś w stanie pomóc ?