I have two tables table1
= records, table2
= duplicates. Both tables contain a variable number of columns at any given time and they both contain the exact same columns with the exception of table2
having an additional ID
column... Both tables contain a column, user_id
. The data comes from a CSV import. If the user_id
already exists in table1
it is inserted into table2
.
With table2
I need to be able to grab all the rows and print them out in a table, no problem. The part I'm having a hard time figuring out... For each column in table2
that gets printed I need to check if the data matches(based on the user_id
) the data in table1
and somehow flag it... (maybe a different color background on the table cell)
Example:
table1
contains the row:
user_id | user_name
-------------------
2342342 | some name
and table2
:
user_id | user_name
-------------------
2342342 | different name
then the output would be:
-----------------------------------------
|2342342 | *flag* different name *flag* |
-----------------------------------------
Any idea as to how I could make this work? If it helps any, I'm building this app with Codeigniter.
This query will select all the entries from table2, and if the name is different than the name in table1,
is_different
will be 1, otherwise it's 0:EDIT
You can do several of those tests in one query, if you need to compare more than one column:
Use this simple join. PHP shouldn't bother with data selecting and ordering, your RDBMS do the job.
I think the best way is
I think it's best that you use an sql query for this. For example:
then your script can check all the fields you want to compare and optionally print the 2 values side by side.
you can print each record returned, and under the mismatches, print a second row containing the original values for easy comparison: