1

my mysql db

ID platos mhkos 
1    22    33
2    15   12

search by ID and result = platos + mhkos how to ?

my code is

    <?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);
?>
2
  • Your question seems unclear to me. Would you please give the example of what you're trying to achieve? Commented Jul 24, 2011 at 19:15
  • Did you mean how to get the sum of two columns? If yes, please edit the title of the question. Commented Jul 24, 2011 at 19:24

2 Answers 2

1

It seems as though what the OP means is sum of two COLUMNS in one ROW.

SELECT platos + mhkos AS totals FROM carpets_1 WHERE id = %s

If the OP wants sum of all columns and rows it would be

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

The question does seem quite confusing, though. Hence me leaning toward the initial two columns and one row.

Sign up to request clarification or add additional context in comments.

Comments

0
SELECT platos + mhkos AS totals FROM carpets_1 WHERE id = %s

2 Comments

This will only sum a row, not 2 rows. CMIIW.
Please edit your question then and make it clearer what you are trying to sum; and given the data you provide, give the answer to that sum as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.