Re: How can I find database records that were NOT just updated
| From: | Reuben D Budiardja | Date: | Sun, 19 Nov 2000 02:34:12 +0000 |
| Subject: | Re: How can I find database records that were NOT just updated | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-26095@lists.php.net to get a copy of this message | ||
There is a built in function array_diff for php4 that should do what you want, that might be more efficient:
$array_were_not_updated = array_diff($array1, $array2);
http://www.php.net/manual/function.array-diff.php
Reuben D. Budiardja
At 09:01 PM 11/19/00 -0500, Chris Carbaugh wrote:
OK, let me first explain what I'm trying to do: I have a table with about 100 records. Each record has a unique ID. A script then adds records to this table, or updates the record if it already exists (based on the ID). I then need to get a list of all the records that were NOT just inserted or updated. The only way I can think of to do this is as follows: I define two single dimension arrays:the first one ($array1) contains the ID's of every record in the tablebefore it is updatedthe second one ($array2) conatins the ID's of every record that wasinserted or updated I then do something like:$i = 0; while ($array1[$i]){ $j = 0; while ($array2[$j]){ if ($array1[$i] == $array2[$j]){ < delete $array1[$i] from $array1 > } $j++; } $i++; }This way though, I have to traverse array2 once for every element in array1. With both arrays being ~100 elements (and they will grow), this will take some time. Anybody have a more efficient way of doing this? Thanks, Chris -- "Without the threat of death, there's no reason to live at all" - Marilyn Manson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net