calculate sum total of all the figures in a column

后端 未结 3 893
青春惊慌失措
青春惊慌失措 2020-12-22 10:46

\"table

I have a table that I want to calculate the sum total of all the values in column \"Price\"

相关标签:
3条回答
  • 2020-12-22 11:17
    mysql_connect($hostname, $username, $password);
    mysql_select_db($db);
    
    $sql = "select sum(column) from table";
    $q = mysql_query($sql);
    $row = mysql_fetch_array($q);
    
    echo 'Sum: ' . $row[0];
    

    Replace variable names and table/column names as needed.

    0 讨论(0)
  • 2020-12-22 11:17

    Do you have any database connection? If not, you should read up on using MySQL in PHP.

    If you do already know how to connect, you can still use that same example. :)

    0 讨论(0)
  • 2020-12-22 11:22

    Do your select.

    Get the value.

    Echo it.

    Thats just as much as I can help right now since i have no idea what you tried so far.

    For example:

    $some_q = " SELECT SUM(some_col) AS `count_col` FROM some_table";
    
    $results = mysql_query($some_q) or die(mysql_error());
    
    while($row = mysql_fetch_array($results)){
         echo $row['count_col'];
    }
    
    0 讨论(0)
提交回复
热议问题