search

Home  >  Q&A  >  body text

PHP data statistics sum

How to count the sum of all the data in a certain field in the table, and how to output the result?

淡淡烟草味淡淡烟草味2811 days ago683

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 13:12:29

    Thanks for the invitation

    $updataquery = "select  sum(lv) AS the_result from gti_enews_technology_group" ;
    $r=$empire->fetch1($updataquery);
    print_r($r);
    
    
    //打印的结果是Array ( [0] => 252 [the_result] => 252 )  打印看看是什么就好处理了

    reply
    0
  • 某草草

    某草草2017-05-16 13:12:29

    If it is MySQL, there are built-in functions directlySUM:

    SELECT SUM(column) FROM table WHERE conditions;

    Reference https://dev.mysql.com/doc/ref...

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:12:29

    If you directly use SQL statements to sum, it is not good if the data volume is large. Therefore, it is better to take out the value of this field first. If the amount of data is large, sum it up piece by piece and then integrate it.

    reply
    0
  • Cancelreply