Hi everyone,
I am trying to figure out the best way to map feed data I am obtaining from external sources and change specific data that is going to be imported into my MySQL table into my local standards/MySQL data types. Trying to do this because different feeds have different info and trying to get multiple feeds into one table because products are highly related.
I am currently trying to use an array to help with the mapping of external data to local data but any suggestions are welcome.
What I am currently using:
$field_mapping = array('DisplayYN' => array( 'Yes' => 1,
'True' => 1,
'No' => 0,
'False' => 0)
);
$line = "id,DisplayYN,Status";
$keys = explode(",", trim($line));
$line2 = "1,True,Out of Stock";
$pieces = explode("```", trim($line2));
$this_record = Array();
for($j = 0; $j < count($keys); $j++) {
if(array_key_exists("{$keys[$j]}",$field_mapping)){
if ($field_mapping["{$keys[$j]}"]["$pieces[$j]"]) {
$this_record[] = mysql_real_escape_string($field_mapping["{$keys[$j]}"][$pieces[$j]]);
}
} else {
$this_record[] = mysql_real_escape_string($pieces[$j]);
}
}
Is this an appropriate way to map data from one source to another? Or is there a better way to approach this?
Basically I am just trying to map certain fields to my standards, if needed, and then leaving the rest of the incoming fields alone.
Thanks for the help!