How do I bulk process mysql data using PHP? Hope that the master can directly give the code, thank you!

Source: Internet
Author: User
For example, there are several data in the database that want to add and insert two fields from each piece of data into another field:

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 single calculation is as follows:
 
  SimpleQuery ($q); $a = $obj _db->fetchrow ($r, DB_FETCHMODE_ASSOC), $CCD = $a [cca]+ $a [CCB]; $obj _db->simplequery (" Update member set ccd= ' $CCD ' where id= ' 5 ' ");? >


Is there any way to calculate each piece of data in batches at once? Please give the detailed code, thank you!


Reply to discussion (solution)

$obj _db->simplequery ("Update member set CCD=CCA+CCB where id= ' 5 '");

$obj _db->simplequery ("Update member set CCD=CCA+CCB where id= ' 5 '");


Praise..

$obj _db->simplequery ("Update member set CCD=CCA+CCB");

$obj _db->simplequery ("Update member set CCD=CCA+CCB");

This is the landlord's request, the whole table once done

This is the standard SQL Ah, and PHP is OK. Grammer:update TableName Set cloum= "where".

$obj _db->simplequery ("Update member set CCD=CCA+CCB");

Thank you very much! Please continue to ask:
If you want to judge the cca+ccb>110 of the calculation, how to write this wrong AH:
$obj _db->simplequery ("Update member set CCD=CCA+CCB where SUM (CCA+CCB) >110");

Please help correct the code, thank you!

Update member set CCD=CCA+CCB where cca+ccb>110

Update member set CCD=CCA+CCB where cca+ccb>110



Thank you

  • 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.