Hi,
I have a database called nielupdate and i want to update the database. the rows which are undated are stored in a text file. so i need to update from the text file to the database. iam not able to do that ...
i have given the code which i used
<?php
session_start();
include("../connect2db.php");
//$user_descrip = $_SESSION['user_descrip'];
$user_descrip="Administrator";
if($user_descrip!="Administrator")
{
header("Location: ../accessdenied.htm");
}
else
{
$table="nielupdate";
//AF
$sql="update $table set custdept='AF' where substring(BIC1,1,1)='F'";
mysql_query($sql);
//JF
$sql="update $table set custdept='JF' where substring(BIC1,1,1)='Y' and substring(BIC1,2,1)='F'";
mysql_query($sql);
//JNF
$sql="update $table set custdept='JNF' where substring(BIC1,1,1)='Y' and substring(BIC1,2,1)!='F'";
mysql_query($sql);
//ANF
$sql="update $table set custdept='ANF' where custdept='' and substring(BIC1,1,1)!='Y' and substring(BIC1,1,1)!='F' and BIC1!=''";
mysql_query($sql);
//Binding Paperback
$sql="update $table set binding='Paperback' where binding='' or binding= 'NULL' and substring(FMC,1,2)='BC'";
mysql_query($sql);
//Binding Hardback
$sql="update $table set binding='Hardback' where binding='' or binding= 'NULL' and substring(FMC,1,2)='BB'";
mysql_query($sql);
//JF
$sql="update $table set custdept='JF' where custdept='' and substring(dw,1,1)='8' and substring(dw,3,1)='3' and (substring(rc,1,1)='S' or substring(rc,1,1)='J' or substring(rc,1,1)='X')";
mysql_query($sql);
//AF
$sql="update $table set custdept='AF' where custdept='' and substring(dw,1,1)='8' and substring(dw,3,1)='3' and (substring(rc,1,1)!='S' or substring(rc,1,1)!='J' or substring(rc,1,1)!='X')";
mysql_query($sql);
//JNF
$sql="update $table set custdept='JNF' where custdept='' and substring(dw,1,1)!='8' and substring(dw,3,1)!='3' and dw!='' and (substring(rc,1,1)='S' or substring(rc,1,1)='J' or substring(rc,1,1)='X')";
mysql_query($sql);
//ANF
$sql="update $table set custdept='ANF' where custdept='' and substring(dw,1,1)!='8' and substring(dw,3,1)!='3' and dw!='' and (substring(rc,1,1)!='S' or substring(rc,1,1)!='J' or substring(rc,1,1)!='X')";
mysql_query($sql);
//fiction Y
$sql="update $table set fiction='Y' where custdept='AF' or custdept='JF'";
mysql_query($sql);
//fiction N
$sql="update $table set fiction='N' where custdept!='AF' and custdept!='JF'";
mysql_query($sql);
//copy date
$sql="update $table set pub_date=PDUK";
mysql_query($sql);
//fix type HW281208
$sql="update $table set type1='BOOKS' where type1=''";
mysql_query($sql);
//Update type1 and binding to BOOKS
$sql0="select catalog_no,fmc from $table";
$res0=mysql_query($sql0);
while($ser0=mysql_fetch_array($res0))
{
$fmc=$ser0['fmc'];
$catalog_no=$ser0['catalog_no'];
$num_rows = mysql_num_rows(mysql_query("select type1 from neilsen_codes where fmc='$fmc'"));
If ($num_rows > 0)
{
$type1=mysql_result(mysql_query("select type1 from neilsen_codes where fmc='$fmc'"),0);
}
$num_rows = mysql_num_rows(mysql_query("select binding from neilsen_codes where fmc='$fmc'"));
If ($num_rows > 0)
{
$binding=mysql_result(mysql_query("select binding from neilsen_codes where fmc='$fmc'"),0);
}
mysql_query("update $table set type1='$type1' where catalog_no='$catalog_no'");
mysql_query("update $table set binding='$binding' where catalog_no='$catalog_no'");
}
//update the entire table
$sql="load data infile W:\Nielsen13_Data\upd_20090527c.txt replace into table $table";
//$sql="insert ignore into $table select * from W:\Nielsen13_Data\upd_20090527c.txt";
//$sql="INSERT INTO $table SELECT ON DUPLICATE KEY UPDATE W:\Nielsen13_Data\upd_20090527c.txt";
mysql_query($sql);
if ($table != 0)
{
echo 'Updated';
}
else
{
echo 'Not Updated';
}
}
?>
thanks,
sun11
I have a database called nielupdate and i want to update the database. the rows which are undated are stored in a text file. so i need to update from the text file to the database. iam not able to do that ...
i have given the code which i used
<?php
session_start();
include("../connect2db.php");
//$user_descrip = $_SESSION['user_descrip'];
$user_descrip="Administrator";
if($user_descrip!="Administrator")
{
header("Location: ../accessdenied.htm");
}
else
{
$table="nielupdate";
//AF
$sql="update $table set custdept='AF' where substring(BIC1,1,1)='F'";
mysql_query($sql);
//JF
$sql="update $table set custdept='JF' where substring(BIC1,1,1)='Y' and substring(BIC1,2,1)='F'";
mysql_query($sql);
//JNF
$sql="update $table set custdept='JNF' where substring(BIC1,1,1)='Y' and substring(BIC1,2,1)!='F'";
mysql_query($sql);
//ANF
$sql="update $table set custdept='ANF' where custdept='' and substring(BIC1,1,1)!='Y' and substring(BIC1,1,1)!='F' and BIC1!=''";
mysql_query($sql);
//Binding Paperback
$sql="update $table set binding='Paperback' where binding='' or binding= 'NULL' and substring(FMC,1,2)='BC'";
mysql_query($sql);
//Binding Hardback
$sql="update $table set binding='Hardback' where binding='' or binding= 'NULL' and substring(FMC,1,2)='BB'";
mysql_query($sql);
//JF
$sql="update $table set custdept='JF' where custdept='' and substring(dw,1,1)='8' and substring(dw,3,1)='3' and (substring(rc,1,1)='S' or substring(rc,1,1)='J' or substring(rc,1,1)='X')";
mysql_query($sql);
//AF
$sql="update $table set custdept='AF' where custdept='' and substring(dw,1,1)='8' and substring(dw,3,1)='3' and (substring(rc,1,1)!='S' or substring(rc,1,1)!='J' or substring(rc,1,1)!='X')";
mysql_query($sql);
//JNF
$sql="update $table set custdept='JNF' where custdept='' and substring(dw,1,1)!='8' and substring(dw,3,1)!='3' and dw!='' and (substring(rc,1,1)='S' or substring(rc,1,1)='J' or substring(rc,1,1)='X')";
mysql_query($sql);
//ANF
$sql="update $table set custdept='ANF' where custdept='' and substring(dw,1,1)!='8' and substring(dw,3,1)!='3' and dw!='' and (substring(rc,1,1)!='S' or substring(rc,1,1)!='J' or substring(rc,1,1)!='X')";
mysql_query($sql);
//fiction Y
$sql="update $table set fiction='Y' where custdept='AF' or custdept='JF'";
mysql_query($sql);
//fiction N
$sql="update $table set fiction='N' where custdept!='AF' and custdept!='JF'";
mysql_query($sql);
//copy date
$sql="update $table set pub_date=PDUK";
mysql_query($sql);
//fix type HW281208
$sql="update $table set type1='BOOKS' where type1=''";
mysql_query($sql);
//Update type1 and binding to BOOKS
$sql0="select catalog_no,fmc from $table";
$res0=mysql_query($sql0);
while($ser0=mysql_fetch_array($res0))
{
$fmc=$ser0['fmc'];
$catalog_no=$ser0['catalog_no'];
$num_rows = mysql_num_rows(mysql_query("select type1 from neilsen_codes where fmc='$fmc'"));
If ($num_rows > 0)
{
$type1=mysql_result(mysql_query("select type1 from neilsen_codes where fmc='$fmc'"),0);
}
$num_rows = mysql_num_rows(mysql_query("select binding from neilsen_codes where fmc='$fmc'"));
If ($num_rows > 0)
{
$binding=mysql_result(mysql_query("select binding from neilsen_codes where fmc='$fmc'"),0);
}
mysql_query("update $table set type1='$type1' where catalog_no='$catalog_no'");
mysql_query("update $table set binding='$binding' where catalog_no='$catalog_no'");
}
//update the entire table
$sql="load data infile W:\Nielsen13_Data\upd_20090527c.txt replace into table $table";
//$sql="insert ignore into $table select * from W:\Nielsen13_Data\upd_20090527c.txt";
//$sql="INSERT INTO $table SELECT ON DUPLICATE KEY UPDATE W:\Nielsen13_Data\upd_20090527c.txt";
mysql_query($sql);
if ($table != 0)
{
echo 'Updated';
}
else
{
echo 'Not Updated';
}
}
?>
thanks,
sun11