0

I have this PHP Code that selects from a database and creates an array with the data

$sql="SELECT * from voip_emergency_services_data ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
if(mysql_num_rows($rs) > 0)
{
    while($result=mysql_fetch_array($rs))
    {
        $ListData1[] = $result["number"];
    }
}

this one does the same on a different table, also connecting to a different database on a different server

$sql="SELECT * from channel_did ";
$rs=mysql_query($sql,$pbx01_conn) or die(mysql_error());
if(mysql_num_rows($rs) > 0)
{
    while($result=mysql_fetch_array($rs))
    {
        $ListData2[] = $result["did"];
    }
}

how can i match the data in both of the Arrays and then display what does not match

for example, each row in the channel_did table should match with a row in the voip_emergency_services_data table based on the did column and the number column

1
  • Different database on a different server? Can you not use the FEDERATED storage engine to link them? Commented Oct 31, 2013 at 20:32

2 Answers 2

1

Based on the question, this gives what is in 1 but not in 2 and what is in 2 but not in 1:

$notIn1 = array_diff($ListData2, $ListData1);
$notIn2 = array_diff($ListData1, $ListData2);

echo implode(',', $notIn1) . ' are in list 2 but not 1';
echo implode(',', $notIn2) . ' are in list 1 but not 2';

foreach($notIn1 as $value) {
    echo "$value is not in list 1";
}
Sign up to request clarification or add additional context in comments.

6 Comments

i am getting these errors: Warning: array_diff() [function.array-diff]: Argument #1 is not an array in /home/integra/public_html/admin/customer/voip_emergency_data_errors.php on line 37 Warning: array_diff() [function.array-diff]: Argument #1 is not an array in /home/integra/public_html/admin/customer/voip_emergency_data_errors.php on line 42
i now just get the word 'Array' nothing else :(
so i need to do anything with the arrays after outside the loop?
Well sure, you didn't ask anything about that. Do you need to know how to display array values? That's a different question. Either implode() or foreach and echo.
you mean you get the word 'Array' when trying to display the contents of $notIn1 and $notIn2? how are you trying to do so?
|
0

There are a couple of functions you can use that would solve this.

array_diff($array1,$array2) will find all items that are in $array1 but not $array2.

array_intersect($array1,$array2) will find all items that are in $array1 and $array2. $array1 will be the master that is being compared against, so array2 can contain items that are not in $array1.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.