Jump to content

mcastu

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mcastu's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hi... i m new in this forum.... i have a table(at0310) having fields: ecardno,atdate,attime,serialno,cardrd and ecode my all fields having values dat comes from a text file dat i already done .......... but ecode is empty and i want this ecode comes from another table from same database i.e emp_company. In emp_company i have field ecardno and ecode .. so i want at0310 table dat ecardno matches with emp_company's ecardno and return the ecodeno correspondence it and update dat ecode into at0310 table........... in my code the problem is that ecode is updated but only one ecode is update everytime for each record... <html> <?php $con=mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('master',$con); $file = "ATND.txt"; $fp = fopen($file, "r"); $data = fread($fp, filesize($file)); fclose($fp); $output = str_replace("\t"," ", $data); $output = explode("\n", $output); foreach($output as $var) { $tmp = explode(" ", $var); $ecardno = $tmp[0]; $cluster = $tmp[1]; $atdate = substr($tmp[1],0,6); $attime = substr($tmp[1],6,4); $IO = substr($tmp[1],10,1); $serialno = substr($tmp[1],11,5); $cardrd = substr($tmp[1],16); $sql = "INSERT INTO at0310 SET ecardno='$ecardno', atdate='$atdate',attime='$attime',IO='$IO',serialno='$serialno',cardrd='$cardrd'"; //"INSERT INTO at0310 SET ecardno='$ecardno', atdate='$atdate',attime='$attime',IO='$IO',serialno='$serialno',cardrd='$cardrd' "; //$sql ="INSERT INTO at0310 ('$ecardno','$atdate','$attime','$IO','$serialno','$cardrd','$ecode') //SELECT ecode FROM emp_company GROUP BY ('$ecode')"; mysql_query($sql); } include("instxtecode.php"); echo "Done!"; ?> <head> <title></title> </head> <body> <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("master", $con); $query=mysql_query("SELECT emp_company.ecode FROM emp_company INNER JOIN at0310 ON emp_company.ecardno = at0310.ecardno")or die(mysql_error()); while($row=mysql_fetch_array($query)) { $ecode=$row['ecode']; mysql_query("UPDATE at0310 SET ecode='$ecode'")or die(mysql_error()); } if (mysql_query($query, $con)) { echo "record updated !"; } else { echo"something went wrong"; } mysql_close($con) ?> </BODY> </HTML>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.