How do I insert all the records in another table when I process MySQL data in bulk? The master can give the code directly, thank you

Source: Internet
Author: User
How do I insert all the records in another table when I process MySQL data in bulk? Please master can directly give the code, thank you!
For example, there are several data in the Database member table, you want to add two fields in each data, CCA and CCB, and insert into another field CCD:

CCA CCB CCD ID
45 66 0 1
67 36 0 2
86 24 0 5
76 84 0 8
6 55 0 12
The code is as follows:
$obj _db->simplequery ("Update member set CCD=CCA+CCB");


The result is:
CCA CCB CCD ID
45 66 111 1
67 36 103 2
86 24 110 5
76 84 160 8
6 55 61 12
Is the result I want to get.

But I also want to record all the details in another table if I do one of the following:
$id = 12;
$obj _db->simplequery ("Update member set CCD=CCA+CCB where id= ' $id '");


$q = "SELECT * from member where id= ' $id '";
$r = $obj _db->simplequery ($q);
$a = $obj _db->fetchrow ($r, DB_FETCHMODE_ASSOC);

$MCCD = $a [cca]+ $a [CCB];

$query = "INSERT into Mingxi (mid,mccd,mtime) VALUES (' $id ', ' $MCCD ', ' $time ')";
$obj _db->simplequery ($query);


Get:
Mid MCCD Mtime ID
12 61 1394963723 1


But how to get in bulk:
Mid MCCD Mtime ID
1 111 1394963723 1
2 103 1394963723 2
5 110 1394963723 3
8 160 1394963723 4
12 61 1394963723 5

Please help the expert to give detailed code, thank you!
------Solution--------------------
$id = 12;
$obj _db->simplequery ("Update member set CCD=CCA+CCB");


$q = "SELECT * from member '";
$r = $obj _db->simplequery ($q);
while ($a = $obj _db->fetchrow ($r, Db_fetchmode_assoc)) {
$id = $a [id];
$MCCD = $a [cca]+ $a [CCB];

$query = "INSERT into Mingxi (mid,mccd,mtime) VALUES (' $id ', ' $MCCD ', ' $time ')";
$obj _db->simplequery ($query);
}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.