Update:
What I am actually doing:
I am making an ETL tool and writing its script in php:
ETL is being designed for specific domain, the provided data is consistent with its structure but there is some dirtyness in the data which is needed to be removed like H.NO , H#, H.NO. should be = HNO :
I am using approach of stored procedure. In which i created a lookup table for wrong values and replacing them with right values so the final stored data should be perfect.
I have to detect the wrong values in the db table and replace them with the right one’s thats all.
I have created an array $find[] that is storing values coming from DB, Then there is a variable $exist , which i want to check if it exists in the $find[wrong] array (column) or not. If It does then its value gets replace with the correspnding cloumn value $find[right]. Kindly let me know how can i do such sort of replacement. Thanks,
Note : My DB table contains only two columns named as wrong and right
When I dump my $find array it gave me the following output:
Array ( [0] => Array ( [0] => FSc [wrong] => FSc [1] => FSC [right] => FSC ) [1] => Array ( [0] => Fsc [wrong] => Fsc [1] => FSC [right] => FSC )
CODE:
$lookup = mysql_query("select * from lookup");
while($getlookup = mysql_fetch_array($lookup))
{
$find[] = $getlookup;
}
print_r($find);
OK you need to simply change your query to this
This will return 0 rows if there is no match. Or one (or more rows depending on how table is setup) if there is a match.
You should have an index on your
wrongfield to optimize the query. If there should only be one specific value ofrightfor any value ofwrong(i.e.wrongis unique on each row), then makewronga unique index to enforce it’s uniqueness.Updated answer to match your revised question. What I would do is simply use an SQL query to update your bad data from your mapping table.
So I am assuming you DB structure could look something like this:
Then the query you would need to run to update the table with sanitized values would like this
This would update the table in place to the new values. Obviously, if you didn’t want to change the table in place, you could make a copy of the table and then run this query against that table copy.