ok...i'm trying to read the files from a directory, pass these to an array ($files) and compare these to what is in the database (temp)...i want it to return ONLY the values that ARE NOT in the db...
so...if xyz.html is in the directory and not in the db it would be output...
it seems that array_diff is the way to go, but i also tried array_merge with array_unique and got basically the same results...
i think i've diagnosed the problem...the array from the directory does not sort the files in any particular way...so when it compares them to the query from the db only the first or sometimes the second values are calculated properly...then it's so completely out of order it just doesn't work (i spent some time adding and deleting from the db to test this out)...
now...anybody have any thoughts about how to resolve this? can i somehow ORDER my $files array from the directory?
this is my code...it's doing it's job...but i'm missing out on the ordering part of things...if anybody has any other means or methods to try please advise...
thanks...jv
<?
////dbconnectinfo...
$sql = "SELECT * FROM temp2 ORDER BY html ASC";
$result = mysql_query ($sql) or DIE ("Unexpected Erro for MySQL Database" .mysql_error());
$rows = mysql_fetch_array ($result);
$handle = opendir('.') OR DIE ("can not open dir");
while ($file = readdir ($handle)) {
if ($file != "." && $file != "..") {
$files[] = $file;
}
}
$myArr = array_diff ($files, $rows);
this could be also (but i think array_diff is the way to go overall):
$myArr = array_merge ($files, $rows);
$myArr = array_unique ($myArr);
for ($i=0; $i<count($myArr); $i++) {
print $myArr[$i];
}
closedir ($handle);
?>