$dbcnx = @mysql_connect('mysql.plainhost.com', 'ecosmar_ecosmart', 'ecoman1');
mysql_select_db('ecosmar_products', $dbcnx);
$dtnum = date(Ymd)*1;
$outage = $_POST[outage];
$newthem = $_POST[newthem];
$newthe = array_shift($newthem);
$countthem = count($newthem);
$countyes = 0;
foreach($newthem as $value){
$gem = explode('|', $value);
$chk = mysql_query("SELECT * FROM price WHERE item='$gem[0]'");
if(!$chk){
echo(" Something is wrong. Cannot check for duplicate. ".mysql_error()." ");
}else{
$rochk = mysql_fetch_array($chk);
if($rochk[0] == ""){
if($gem[0] != ""){
$into = mysql_query("INSERT INTO price SET item='$gem[0]',sku='$gem[1]',list='$gem[2]',retail='$gem[3]',special='$gem[4]',dealer='$gem[5]',dealer_lo='$gem[6]',distributor='$gem[7]',cost='$gem[8]',unit='$gem[9]',lo_units='$gem[10]',cs='$gem[11]',min='$gem[12]',up_date='$dtnum',description='$gem[14]'");
if(!$into){
echo("Could not insert new row for $gem[0] ".mysql_error()." ");
}else{
$countyes = $countyes + 1;
}
}else{
$countyes = $countyes + 1;
}
}elseif($rochk[0] != ""){
$result = array_diff_assoc($rochk, $gem);
if(empty($result)){
$countyes = $countyes + 1;
}else{
$uppit = mysql_query("UPDATE price SET sku='$gem[1]',list='$gem[2]',retail='$gem[3]',special='$gem[4]',dealer='$gem[5]',dealer_lo='$gem[6]',distributor='$gem[7]',cost='$gem[8]',unit='$gem[9]',lo_units='$gem[10]',cs='$gem[11]',min='$gem[12]',up_date='$dtnum',description='$gem[14]' WHERE item='$gem[0]'");
if(!$uppit){
echo("Could not update $gem[0] ".mysql_error()." ");
}else{
$countyes = $countyes + 1;
}
}
}
}
}//4each
if(!empty($outage)){
foreach($outage as $value){
$out = mysql_query("DELETE FROM price WHERE item='$value' LIMIT 1");
if(!out){
echo("Could not delete ".$value." ".mysql_error()." ");
}else{
echo("$value Deleted, ");
}
}//4ea
$sql = mysql_query("OPTIMIZE TABLE 'price'");
if($sql){
echo("Data Base Optimization Complete.");
}
}
if($countthem == $countyes){
echo("Successful Update of Price List. ");
}else{
echo("Problems Overwriting Price List. ");
}
?>
|