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);
}