hi writh .........
thanx for last responses....... i need your help agian plz help me out
i have two tables emp_company and at0310
in at0310 having fields: ecardno,atdate,time,IO,serialno,cardrd and ecode.
into my text file ecardno,atdate,time,IO,serialno,cardrd record available but ecode not comes from there
in my emp_compnay i have filed like ecode,ecardno,etc
i want into my at0310 ecode comes from emp_company and only those ecode should be stored into at0310
that matches with ecard with text file.... can you tell me any query .....
according to me select and insert needed but i cant place them in working order
plz help me out waiting for reply
thank you for taking the time to help me out!

<html>
<?php
$con=mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('master',$con);
$ecode=$_POST['ecode'];
//(1) Read the text file into a variable
$file = "ATND.txt";
$fp = fopen($file, "r");
$data = fread($fp, filesize($file));
fclose($fp);
//(2) Then we can get rid of the tabs in there:
$output = str_replace("\t"," ", $data);
//(3) Then we explode it at every line break
$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' (select ecode into at0310 from emp_company where at0310.ecardno=emp_company.ecardno)";
//$sql ="INSERT INTO at0310 ('$ecardno','$atdate','$attime','$IO','$serialno','$cardrd','$ecode')
//SELECT ecode FROM emp_company GROUP BY ('$ecode')";
mysql_query($sql);
}
echo "Done!";
?>

Recommended Answers

All 3 Replies

hi writh .........
thanx for last responses....... i need your help agian plz help me out
i have two tables emp_company and at0310
in at0310 having fields: ecardno,atdate,time,IO,serialno,cardrd and ecode.
into my text file ecardno,atdate,time,IO,serialno,cardrd record available but ecode not comes from there
in my emp_compnay i have filed like ecode,ecardno,etc
i want into my at0310 ecode comes from emp_company and only those ecode should be stored into at0310
that matches with ecard with text file.... can you tell me any query .....
according to me select and insert needed but i cant place them in working order
plz help me out waiting for reply
thank you for taking the time to help me out!

<html>
<?php
$con=mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('master',$con);
$ecode=$_POST['ecode'];
//(1) Read the text file into a variable
$file = "ATND.txt";
$fp = fopen($file, "r");
$data = fread($fp, filesize($file));
fclose($fp);
//(2) Then we can get rid of the tabs in there:
$output = str_replace("\t"," ", $data);
//(3) Then we explode it at every line break
$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' (select ecode into at0310 from emp_company where at0310.ecardno=emp_company.ecardno)";
//$sql ="INSERT INTO at0310 ('$ecardno','$atdate','$attime','$IO','$serialno','$cardrd','$ecode')
//SELECT ecode FROM emp_company GROUP BY ('$ecode')";
mysql_query($sql);
}
echo "Done!";
?>

You were SOOOOOOOOOOOOO close!

$sql ="INSERT INTO `at0310`(`ecardno`,`atdate`,`attime`,`IO`,`serialno`,`cardrd`,`ecode`) VALUES ('$ecardno','$atdate','$attime','$IO','$serialno','$cardrd','$ecode')";

My 2¢. Hope this helps.

P.S. - What class are you in right now? :)

hi writh.
thankz 4 ur hlp.........m making mca final yr project....internship period.........

this is simple insert query ........ but i want something different..........
i got someidea about it how i can insert ecode into my at0310 table from emp_company............ i feel i should use update query...
i used it so many times but desired result not come............. plz help me
about subquery of update ...........
i used dis query- but not working.
UPDATE at0310 SET (at0310.ecode) =( (SELECT ecode FROM emp_company
WHERE emp_company.ecardno = at0310.ecardno))";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.