如何对php mysql中的两行进行求和

如何对php mysql中的两行进行求和,php,sum,Php,Sum,我的mysql数据库 ID platos mhkos 1 22 33 2 15 12 按ID和结果搜索=柏拉图+mhkos如何 我的代码是 <?php require_once('Connections/hlios.php'); ?> <?php echo $row_test['platos']; ?>+ <?php echo $row_test['mhkos']; ?> = <?php if (!function_e

我的mysql数据库

ID platos mhkos 
1    22    33
2    15   12
按ID和结果搜索=柏拉图+mhkos如何

我的代码是

    <?php require_once('Connections/hlios.php'); ?>
<?php echo $row_test['platos']; ?>+ <?php echo $row_test['mhkos']; ?>

= <?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_test = "-1";
if (isset($_GET['client_id'])) {
  $colname_test = $_GET['client_id'];
}
mysql_select_db($database_hlios, $hlios);
$query_test = sprintf("SELECT * FROM carpets_1 WHERE id = %s", GetSQLValueString($colname_test, "int"));
$test = mysql_query($query_test, $hlios) or die(mysql_error());
$row_test = mysql_fetch_assoc($test);
$totalRows_test = mysql_num_rows($test);


mysql_free_result($test);
?>

+ 

=似乎OP的意思是一行中两列的总和

SELECT platos + mhkos AS totals FROM carpets_1 WHERE id = %s
如果OP需要所有列和行的总和,则为

SELECT sum(platos) as totalPlatos, sum(mhkos) as totalMhkos FROM carpets_1

不过,这个问题看起来确实很令人困惑。因此,我倾向于最初的两列和一行。

OP的意思似乎是一行中两列的总和

SELECT platos + mhkos AS totals FROM carpets_1 WHERE id = %s
如果OP需要所有列和行的总和,则为

SELECT sum(platos) as totalPlatos, sum(mhkos) as totalMhkos FROM carpets_1

不过,这个问题看起来确实很令人困惑。因此,我倾向于最初的两列一行。

我似乎不清楚你的问题。你能举个例子说明你想要达到的目标吗?你的意思是如何得到两列的总和吗?如果是,请编辑问题的标题。我似乎不清楚你的问题。你能举个例子说明你想要达到的目标吗?你的意思是如何得到两列的总和吗?如果是,请编辑问题的标题。这将只求和一行,而不是两行。请编辑你的问题,让它更清楚你想总结什么;根据您提供的数据,也给出该总和的答案。这将只对一行进行总和,而不是两行。请编辑你的问题,让它更清楚你想总结什么;根据你提供的数据,也给出这个总数的答案。