//Try to find a matching company name in the system, if not them set contact_company to 0 $q = new w2p_Database_Query(); $q->addQuery('company_id'); $q->addTable('companies'); $q->addWhere('company_name LIKE \'' . mb_trim($pairs['contact_company']) . '\''); $company_id = $q->loadResult(); $pairs['contact_company'] = $company_id ? $company_id : 0; $q->clear(); //Try to find a matching department name in the system, if not them set contact_department to 0 $q->addQuery('dept_id'); $q->addTable('departments'); $q->addWhere('dept_name LIKE \'' . mb_trim($pairs['contact_department']) . '\''); $dept_id = $q->loadResult(); $pairs['contact_department'] = $dept_id ? $dept_id : 0; $q->clear(); $q->updateArray($sql_table, $pairs, 'contact_id'); $q->clear(); $s .= '<td><span style="color:#880000;">There is a duplicate record for ' . $pairs['contact_first_name'] . ' ' . $pairs['contact_last_name'] . ', the record has been updated.</span></td>'; } else { //If the contact has no name, go to the next if (!mb_trim($pairs['contact_first_name'] . ' ' . $pairs['contact_last_name'])) { continue; } $s .= '<td>Adding ' . $pairs['contact_first_name'] . ' ' . $pairs['contact_last_name'] . '.</td>'; //Try to find a matching company name in the system, if not them set contact_company to 0 $q = new w2p_Database_Query(); $q->addQuery('company_id'); $q->addTable('companies'); $q->addWhere('company_name LIKE \'' . mb_trim($pairs['contact_company']) . '\''); $company_id = $q->loadResult(); $pairs['contact_company'] = $company_id ? $company_id : 0;