473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

update one field from one table to another table within same database

hi all
i want to update ecode from emp_company to at0310.update ecode that matches with ecardno of both the tables....i used query for it but update only same ecode for all.............
Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <title></title>
  3. </head>
  4. <body>
  5. <?php
  6. $con = mysql_connect("localhost","root","root");
  7. if (!$con)
  8. {
  9. die('Could not connect: ' . mysql_error());
  10. }
  11. mysql_select_db("master", $con);
  12. $query=mysql_query("SELECT emp_company.ecode FROM emp_company INNER JOIN at0310
  13. ON emp_company.ecardno = at0310.ecardno")or die(mysql_error());
  14. while($row=mysql_fetch_array($query))
  15. {
  16. $ecode=$row['ecode'];
  17. mysql_query("UPDATE at0310 SET ecode='$ecode'")or die(mysql_error());
  18. }
  19.  
  20. if (mysql_query($query, $con))
  21. {
  22. echo "record updated !";
  23. }
  24.    else
  25.    {
  26.    echo"something went wrong";
  27.    }
  28. mysql_close($con)
  29. ?>
  30. </BODY>
  31. </HTML>
  32.  
  33.  
this is coding of at0310 that is from text file download from attendance machine.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <?php
  3. $con=mysql_connect("localhost","root","root");
  4. if (!$con)
  5. {
  6. die('Could not connect: ' . mysql_error());
  7. }
  8. mysql_select_db('master',$con);
  9.  
  10. $file = "ATND.txt";
  11. $fp = fopen($file, "r");
  12. $data = fread($fp, filesize($file));
  13. fclose($fp);
  14. $output = str_replace("\t"," ", $data);
  15. $output = explode("\n", $output);
  16. foreach($output as $var)
  17. {
  18. $tmp = explode(" ", $var);
  19. $ecardno = $tmp[0];
  20. $cluster = $tmp[1];
  21. $atdate = substr($tmp[1],0,6);
  22. $attime = substr($tmp[1],6,4);
  23. $IO = substr($tmp[1],10,1);
  24. $serialno = substr($tmp[1],11,5);
  25. $cardrd = substr($tmp[1],16);
  26. $sql =   "INSERT INTO at0310 SET ecardno='$ecardno', atdate='$atdate',attime='$attime',IO='$IO',serialno='$serialno',cardrd='$cardrd'";
  27.  
  28.  
  29. mysql_query($sql);
  30.  
  31. }
  32.  include("instxtecode.php");
  33. echo "Done!";
  34. ?>
  35.  
Mar 8 '10 #1
0 1048

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get...
8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
9
by: Geraldine Hobley | last post by:
Hello I'm getting the above mentioned error in my applicatio I have a datagrid bound to a datasource like s MyDatagrid.DataSource = Mydataset.Tables(Order) - this all works fine However I...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
4
by: hapnendad | last post by:
In the question statement below Field names are in and variables are in (). All fields referenced are in what I have named the ‘PAR’ Table. Using MS Access 2003, I am working on a project...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.