How to read the total score of the score calculation in the data table and write it to another data table

Source: Internet
Author: User
Help: Urgent! How to read the total score calculated in the data table and write it into another data table? I set a score table tb_xmpf, which contains the project name xmpf_xm, the judge name xmpf_user, and the score xmpf_small_zf given by the judges. now I want to calculate the total score and average score of each project, write the xm_zf and xm_avg columns in the project table tb_xm, and follow the xm_zf output table to get started with PHP. this complicated database call is urgent! How to read the total score calculated in the data table and write it into another data table?
I set a score table tb_xmpf, which contains the project name xmpf_xm, the judge name xmpf_user, and the score xmpf_small_zf given by the judges. now I want to calculate the total score and average score of each project, write the xm_zf and xm_avg columns in the project table tb_xm, and follow the xm_zf output table to get started with PHP. this complicated database call is not very useful. please help me think about it!

Share:


------ Solution --------------------
Connect to the database, and the output by table is also very simple.
$ Query = "select xmpf_xm, sum (xmpf_small_zf) zf, avg (xmpf_small_zf) avg from tb_xmpf group by xmpf_xm"; // query the average score of the total score.

$ Result = mysql_query ($ query );

While ($ row = mysql_fetch_array ($ result )){
$ SQL = "insert into tb_xm (xmpf_xm, xm_zf, xm_avg) values ($ row ['xmpf _ xm '], $ row ['zf'], $ row ['avg']) "; // average score of the total insertion score
Mysql_query ($ SQL );
}

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.