Just a doubt… All my query are almost the same as names and definition but the query content obviously that is Always different. In this case $sql_customers is only here.
May I to repeat some names of variable in each function space ?? without making a mess ??
This one of these. For istance $sql_update is all the same within different queries.
$sql_customers=“SELECT CodAnag AS CustomerID, Ragione sociale
AS CompanyName, NomeContatto AS ContactName, Indirizzo AS Address, Localita AS City, Provincia AS Region, CAP AS PostalCode, Nazione AS Country, Zona, NumeroTelefono AS Phone, NumeroFax AS Fax, Cell AS Mobile, PartitaIVA as VatCode, Codice Fiscale
AS CodFisc, Email, Codag AS SalesmanID, Id anag
AS Id_anag FROM b2b_anagrafica WHERE (((Left(CodAnag,1))=‘C’)) ORDER BY CodAnag”;
sc_lookup(rs, $sql_customers, “conn_mysql_import”);
$thevalues = 'INSERT INTO customers_temp (CustomerID,CompanyName,ContactName,Address,City,Region,PostalCode,Country,Zona,Phone,Fax,Mobile,VatCode, CodFisc, Email,SalesmanID,Id_anag) values ';
foreach($rs as $rec)
{
$thevalues1 = "(";
foreach ($rec as $field)
{
$thevalues1 = $thevalues1 ."’" . str_replace("’", “’”, $field) . “’,”;
}
$thevalues1 = substr($thevalues1, 0, strlen($thevalues1)-1);
$thevalues1 = $thevalues1 . "),";
$thevalues = $thevalues.$thevalues1 ;
}
$thevalues = substr($thevalues, 0, strlen($thevalues)-1).";";
// echo $thevalues;
$sql_temp_table=“CREATE TEMPORARY TABLE IF NOT EXISTS customers_temp LIKE customers”;
$sql_temp_trunc=“TRUNCATE TABLE customers_temp”;
sc_exec_sql($sql_temp_table, “conn_mysql”);
sc_exec_sql($sql_temp_trunc, “conn_mysql”);
sc_exec_sql($thevalues, “conn_mysql”);
$sql_update=“INSERT INTO customers(CustomerID,CompanyName,ContactName,Address,City,Region,PostalCode,Country,Zona,Phone,Fax,Mobile,VatCode, CodFisc, Email, User, Password, UserType, SalesmanID, Active, Admist_priviledge, Id_anag)
SELECT t.CustomerID , t.CompanyName , t.ContactName , t.Address , t.City , t.Region , t.PostalCode , t.Country , t.Zona , t.Phone , t.Fax , t.Mobile , t.VatCode, t.CodFisc, t.Email , t.CustomerID, ‘12345’ , ‘CLI’, t.SalesmanID , ‘Y’, 0, t.Id_anag
FROM customers_temp t ON DUPLICATE KEY UPDATE
CompanyName = t.CompanyName ,
ContactName = t.ContactName ,
Address = t.Address ,
City = t.City ,
Region = t.Region ,
PostalCode = t.PostalCode ,
Country = t.Country ,
Zona = t.Zona ,
Phone = t.Phone ,
Fax = t.Fax ,
Mobile = t.Mobile ,
VatCode = t.VatCode,
CodFisc = t.CodFisc,
Email = t.Email ,
UserType = ‘CLI’ ,
SalesmanID = t.SalesmanID ,
Active = ‘Y’,
Admist_priviledge = 0,
Id_anag = t.Id_anag”;
sc_exec_sql($sql_update, “conn_mysql”);