I want to compare for now, two sets of arrays. I pull data from sql tables and then compare the two. I am using the
PHP Code:
array_diff();
function to compare the two arrays, but its showing it as a empty array. Is that because I am not telling it which demensions to look at? Like
PHP Code:
array_diff($array1[5], $array2[5]);
?
Here is the current code:
PHP Code:
<?php
//Opens a connection to the Warta Database
try {
$wrd1 = new PDO('mysql:host=localhost; dbname=*****', '******', '*****');
$wrd1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$cale = $wrd1->prepare(
"SELECT
start,
end,
repeat_freq,
repeat_int,
repeat_end,
allDay,
category_id,
description,
link,
venue,
address,
city,
state,
zip,
country,
contact,
contact_info,
access,
rsvp
FROM
wp_aec_event
");
//executes SQL statement
$cale->execute();
//Set into array
$result = $cale->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
echo("\n");
//Opens a connection to the 1-sza Database
try {
$wrd2 = new PDO('mysql:host=localhost; dbname=*****', '*******', '**');
$wrd2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$cale1 = $wrd2->prepare(
"SELECT
start,
end,
repeat_freq,
repeat_int,
repeat_end,
allDay,
category_id,
description,
link,
venue,
address,
city,
state,
zip,
country,
contact,
contact_info,
access,
rsvp
FROM
wp_aec_event
");
//executes SQL statement
$cale1->execute();
//set into array
$result1=$cale1->fetchALL(PDO::FETCH_ASSOC);
print_r($result1);
echo("\n");
//testing out php array compare
$compare = array_diff($result, $result1);
print_r($compare);
}
catch (PDOException $ex) {
$msg = $ex->errorInfo;
error_log(var_export($msg, true));
die("<p>Sorry, there was a unrecoverable database error. Debug data has been logged.</p>");
}
}
catch (PDOException $ex) {
$msg = $ex->errorInfo;
error_log(var_export($msg, true));
die("<p>Sorry, there was a unrecoverable database error. Debug data has been logged.</p>");
};
?>
For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.
I suspect you will need to use array_udiff() so that you can access those second dimensions.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks