<?php
$cna=mysql_connect("localhost","root","");
$dbselect = mysql_select_db('migra1', $cna);
$sql0 = "select * from tabla";
$rs = mysql_query($sql0,$cna);
//segunda parte
$i=1;
$cnb = mysql_connect("localhost","root","");
$dbselectb = mysql_select_db('migra1',$cnb);
while ($value = mysql_fetch_array($rs)) {
$sql2 = "select * from tabla where codigo ='".$value['codigo']."' and MARCA='".$value['MARCA']."'";
$rs2 = mysql_query($sql2,$cnb);
$val2 = mysql_fetch_array($rs2);
$codigo = $val2['codigo'];
$marca = $val2['MARCA'];
$i++;
}
mysql_close();
?>
<?php
$cn=mysql_connect("localhost","root","");
$dbselec = mysql_select_db('migra1', $cn);
$sql1 = "select * from tabla";
$r2 = mysql_query($sql1,$cn);
//segunda parte
$a=1;
$cnbs = mysql_connect("localhost","root","");
$dbselectbs = mysql_select_db('migra1',$cnbs);
while ($value2 = mysql_fetch_array($r2)) {
$sql2 = "select * from tabla
where codigo='".$value2['codigo']."' and MARCA='".$value2['MARCA']."'";
$r2 = mysql_query($sql2,$cnbs);
$val22 = mysql_fetch_array($r2);
$codigo2 = $val22['codigo'];
$marca2 = $val22['MARCA'];
$a++;
}
mysql_close();
if($codigo==$codigo2){
$cns=mysql_connect("localhost","root","");
$dbselectb = mysql_select_db('migra2',$cns);
$sql = "REPLACE INTO tabla(
MARCA)
VALUES (
'$marca') ";
}else{
$con= mysql_connect("localhost","root","");
$db = mysql_select_db('migra2',$con);
$sql ="INSERT INTO tabla (
codigo,MARCA) VALUES (
'$codigo',
'$marca')";
}
$result = mysql_query($sql);
mysql_close();
?>