Hi All,
I've been playing around with this for ages and am just about stuck!
I have set up small tests off array_diff, manually feeding entries into arrays and it works fine, but the below does not.
Basically it creates 2 arrays fine, but when using array_diff, it just returns everything in whichever array I specify first ie: it doesn't match anything from the second array. Presumably then there is something about the way I am reading the data in, and array_diff can't match them as strings??
This is the code:
[PHP]
<?php
include("connect.php");
$date_1 = strtotime("-2 sunday");
$date_2 = strtotime("-1 sunday");
$projects_array1 = array(); //array to store ipg project numbers from this query (all items from last week marked as not completed)
$link1 = "SELECT ipg_project_num FROM ids_report WHERE designer='".ucwords($_SESSION['user'])."' AND completed='No' AND UNIX_TIMESTAMP(sys_date) BETWEEN ". $date_1 ." AND ". $date_2 ."";
$res1 = mysql_query($link1) or die(mysql_error());
while ($row1 = mysql_fetch_row($res1)) {
$a = "$row1[0]";
$projects_array1[] = $a;
}
$link2 = "SELECT ipg_project_num FROM projects WHERE designer1='".ucwords($_SESSION['user'])."' AND open_status = 'open' OR designer2='".ucwords($_SESSION['user'])."' AND open_status = 'open' ORDER BY name ASC";
$res2 = mysql_query($link2);
$projects_array2 = array(); //array to store ipg project numbers from this query (all projects the deisnger is on)
while ($row2 = mysql_fetch_row($res2)) {
$b = "$row2[0]";
$projects_array2[] = $b;
}
$ipg_num_list = array_diff($projects_array2, $projects_array1);
echo'1: '; print_r($projects_array1); echo'<br><br>';
echo'2: '; print_r($projects_array2); echo'<br><br> ';
echo'Array_Diff: '; print_r($ipg_num_list); echo'<br><br> ';
?>
[/PHP]
And this is what it would output:
[HTML]
1: Array ( [0] => 0 [1] => 1501 [2] => 1583 )
2: Array ( [0] => 1572 [1] => 1538 [2] => 1500 [3] => 1582 [4] => 1583 [5] => 1148 [6] => 1354 [7] => 1501 [8] => 1608 [9] => 1579 [10] => 1627 [11] => 1567 [12] => 1167 [13] => 1545 )
Array_Diff: Array ( [0] => 1572 [1] => 1538 [2] => 1500 [3] => 1582 [4] => 1583 [5] => 1148 [6] => 1354 [7] => 1501 [8] => 1608 [9] => 1579 [10] => 1627 [11] => 1567 [12] => 1167 [13] => 1545 )
[/HTML]
Any help you can provide is most appreciated!!
Thanks,
JM