array_diff between two different column names?
Posted: Thu May 14, 2009 8:38 pm
I have two MySQL different tables with different column names however they reference the same thing: tag id's.
I'm unable to figure out how to get array_diff to work in the following way, here is a clean simple example of what I'm trying to do...
array_1 (tag id's being $_POST)
1,2,3,4,5,6,7
array_2 (tag id's that already exist in the database table)
1,2,3,4
array_diff (tag id's that don't yet exist and need to be added to the database table)
5,6,7
I'm trying to generate the array_diff in example of what I have above.
Here is the not so clean print_r example of what I have (PHP echo's this out)...
The purpose of all of this is to determine what tags do not already have a record in the relational table for blog tags. Thoughts please?
I'm unable to figure out how to get array_diff to work in the following way, here is a clean simple example of what I'm trying to do...
array_1 (tag id's being $_POST)
1,2,3,4,5,6,7
array_2 (tag id's that already exist in the database table)
1,2,3,4
array_diff (tag id's that don't yet exist and need to be added to the database table)
5,6,7
I'm trying to generate the array_diff in example of what I have above.
Here is the not so clean print_r example of what I have (PHP echo's this out)...
What do I need to do in order to get array_diff to work as desired?All Tags ID's: Array ( [0] => 1 [tag_id] => 1 ) , Array ( [0] => 2 [tag_id] => 2 ) , Array ( [0] => 3 [tag_id] => 3 ) , Array ( [0] => 4 [tag_id] => 4 ) , Array ( [0] => 5 [tag_id] => 5 ) , Array ( [0] => 6 [tag_id] => 6 ) , Array ( [0] => 7 [tag_id] => 7 )
Existing Tags: Array ( [0] => 1 [xhref_tag_id] => 1 ) , Array ( [0] => 2 [xhref_tag_id] => 2 ) , Array ( [0] => 3 [xhref_tag_id] => 3 )
Add Tags: Array ( [0] => 7 [tag_id] => 7 )
The purpose of all of this is to determine what tags do not already have a record in the relational table for blog tags. Thoughts please?