Trying to SUM two separate columns but not together as part of a search resultindex doesn't work...
How to cover method return statement in Apex Class?
System.QueryException unexpected token
What is the evidence for the "tyranny of the majority problem" in a direct democracy context?
Quoting Keynes in a lecture
How to explain what's wrong with this application of the chain rule?
Angel of Condemnation - Exile creature with second ability
Is aluminum electrical wire used on aircraft?
Mimic lecturing on blackboard, facing audience
Strong empirical falsification of quantum mechanics based on vacuum energy density
Why is this estimator biased?
Mixing PEX brands
Can I still be respawned if I die by falling off the map?
Why can Carol Danvers change her suit colours in the first place?
How to hide some fields of struct in C?
What to do when eye contact makes your subordinate uncomfortable?
Is this toilet slogan correct usage of the English language?
Probability that THHT occurs in a sequence of 10 coin tosses
putting logo on same line but after title, latex
Store Credit Card Information in Password Manager?
creating a ":KeepCursor" command
What exact color does ozone gas have?
Novel, Lo Tech SF/Fantasy
When were female captains banned from Starfleet?
Invalid date error by date command
Trying to SUM two separate columns but not together as part of a search result
index doesn't work properlyConnecting to MYSQL on an EC2 instanceQuotation and invoice mysql tableMySQL indexing issue when trying to search for a part of a string/wordMySQL is trimming my numbers and I can't figure out whyHow can I execute multiple procedures continuously?Trying to update timestamp using FROM_UNIXTIMEIn PHP MySQL how to sum or not sum multiple columns?Aggregate row sum two columns on table from same keyHow to group same columns from same two tables, but from two different result sets and/or conditions
Code below:
$db = new PDO($dsn, $username, $password, $options);
$db1 = new PDO($dsn, $username, $password, $options);
$db2 = new PDO($dsn, $username, $password, $options);
$sql = "SELECT
*
FROM joblist
WHERE customer = :customer";
$sql_val = "SELECT customer,
SUM(value) AS total_value
FROM joblist
GROUP By customer";
$sql_bal = "SELECT customer,
SUM(balance) AS total_balance
FROM joblist
GROUP By customer";
//var_dump($sql_bal);
$customer = $_POST['customer'];
$statement = $db->prepare($sql);
$statement->bindParam(':customer', $customer, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
// total SUM for value
$stmt = $db1->prepare($sql_val);
$stmt->execute();
$totalv = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$sumv = array_sum(array_column($totalv, 'total_value'));
var_dump($totalv);
// total SUM for balance
$stmt1 = $db2->prepare($sql_bal);
$stmt1->execute();
$totalb = $stmt1->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$sumb = array_sum(array_column($totalb, 'total_balance'));
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
die();
}
}
the table is joblist, columns are work_order, customer, description, value, balance, staus and notes.
Current code in this screen works to the extent that it pulls data into my HTML table, I just need to fnd out how to pull the data in the array into the totals spot in the HTML table.
Here is an example of the table..

Ok i have touched this up, likely not correct but I am getting a var_dump from my array. I just don't know how to get the array into the HTML table now.
Link to my current code work
mysql php
New contributor
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Code below:
$db = new PDO($dsn, $username, $password, $options);
$db1 = new PDO($dsn, $username, $password, $options);
$db2 = new PDO($dsn, $username, $password, $options);
$sql = "SELECT
*
FROM joblist
WHERE customer = :customer";
$sql_val = "SELECT customer,
SUM(value) AS total_value
FROM joblist
GROUP By customer";
$sql_bal = "SELECT customer,
SUM(balance) AS total_balance
FROM joblist
GROUP By customer";
//var_dump($sql_bal);
$customer = $_POST['customer'];
$statement = $db->prepare($sql);
$statement->bindParam(':customer', $customer, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
// total SUM for value
$stmt = $db1->prepare($sql_val);
$stmt->execute();
$totalv = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$sumv = array_sum(array_column($totalv, 'total_value'));
var_dump($totalv);
// total SUM for balance
$stmt1 = $db2->prepare($sql_bal);
$stmt1->execute();
$totalb = $stmt1->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$sumb = array_sum(array_column($totalb, 'total_balance'));
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
die();
}
}
the table is joblist, columns are work_order, customer, description, value, balance, staus and notes.
Current code in this screen works to the extent that it pulls data into my HTML table, I just need to fnd out how to pull the data in the array into the totals spot in the HTML table.
Here is an example of the table..

Ok i have touched this up, likely not correct but I am getting a var_dump from my array. I just don't know how to get the array into the HTML table now.
Link to my current code work
mysql php
New contributor
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Why theWHERE value = :total_value...? What is it you want to show? A small sample of rows with wanted output would help.
– ypercubeᵀᴹ
yesterday
total_value I was trying to use a place holder for the SUM data to echo out to a line like I say I'm no guru on this stuff. just trying to get through it :)
– freebs
yesterday
add a comment |
Code below:
$db = new PDO($dsn, $username, $password, $options);
$db1 = new PDO($dsn, $username, $password, $options);
$db2 = new PDO($dsn, $username, $password, $options);
$sql = "SELECT
*
FROM joblist
WHERE customer = :customer";
$sql_val = "SELECT customer,
SUM(value) AS total_value
FROM joblist
GROUP By customer";
$sql_bal = "SELECT customer,
SUM(balance) AS total_balance
FROM joblist
GROUP By customer";
//var_dump($sql_bal);
$customer = $_POST['customer'];
$statement = $db->prepare($sql);
$statement->bindParam(':customer', $customer, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
// total SUM for value
$stmt = $db1->prepare($sql_val);
$stmt->execute();
$totalv = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$sumv = array_sum(array_column($totalv, 'total_value'));
var_dump($totalv);
// total SUM for balance
$stmt1 = $db2->prepare($sql_bal);
$stmt1->execute();
$totalb = $stmt1->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$sumb = array_sum(array_column($totalb, 'total_balance'));
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
die();
}
}
the table is joblist, columns are work_order, customer, description, value, balance, staus and notes.
Current code in this screen works to the extent that it pulls data into my HTML table, I just need to fnd out how to pull the data in the array into the totals spot in the HTML table.
Here is an example of the table..

Ok i have touched this up, likely not correct but I am getting a var_dump from my array. I just don't know how to get the array into the HTML table now.
Link to my current code work
mysql php
New contributor
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Code below:
$db = new PDO($dsn, $username, $password, $options);
$db1 = new PDO($dsn, $username, $password, $options);
$db2 = new PDO($dsn, $username, $password, $options);
$sql = "SELECT
*
FROM joblist
WHERE customer = :customer";
$sql_val = "SELECT customer,
SUM(value) AS total_value
FROM joblist
GROUP By customer";
$sql_bal = "SELECT customer,
SUM(balance) AS total_balance
FROM joblist
GROUP By customer";
//var_dump($sql_bal);
$customer = $_POST['customer'];
$statement = $db->prepare($sql);
$statement->bindParam(':customer', $customer, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
// total SUM for value
$stmt = $db1->prepare($sql_val);
$stmt->execute();
$totalv = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$sumv = array_sum(array_column($totalv, 'total_value'));
var_dump($totalv);
// total SUM for balance
$stmt1 = $db2->prepare($sql_bal);
$stmt1->execute();
$totalb = $stmt1->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$sumb = array_sum(array_column($totalb, 'total_balance'));
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
die();
}
}
the table is joblist, columns are work_order, customer, description, value, balance, staus and notes.
Current code in this screen works to the extent that it pulls data into my HTML table, I just need to fnd out how to pull the data in the array into the totals spot in the HTML table.
Here is an example of the table..

Ok i have touched this up, likely not correct but I am getting a var_dump from my array. I just don't know how to get the array into the HTML table now.
Link to my current code work
mysql php
mysql php
New contributor
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 5 mins ago
freebs
New contributor
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
freebsfreebs
11
11
New contributor
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
freebs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Why theWHERE value = :total_value...? What is it you want to show? A small sample of rows with wanted output would help.
– ypercubeᵀᴹ
yesterday
total_value I was trying to use a place holder for the SUM data to echo out to a line like I say I'm no guru on this stuff. just trying to get through it :)
– freebs
yesterday
add a comment |
1
Why theWHERE value = :total_value...? What is it you want to show? A small sample of rows with wanted output would help.
– ypercubeᵀᴹ
yesterday
total_value I was trying to use a place holder for the SUM data to echo out to a line like I say I'm no guru on this stuff. just trying to get through it :)
– freebs
yesterday
1
1
Why the
WHERE value = :total_value... ? What is it you want to show? A small sample of rows with wanted output would help.– ypercubeᵀᴹ
yesterday
Why the
WHERE value = :total_value... ? What is it you want to show? A small sample of rows with wanted output would help.– ypercubeᵀᴹ
yesterday
total_value I was trying to use a place holder for the SUM data to echo out to a line like I say I'm no guru on this stuff. just trying to get through it :)
– freebs
yesterday
total_value I was trying to use a place holder for the SUM data to echo out to a line like I say I'm no guru on this stuff. just trying to get through it :)
– freebs
yesterday
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
freebs is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f232681%2ftrying-to-sum-two-separate-columns-but-not-together-as-part-of-a-search-result%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
freebs is a new contributor. Be nice, and check out our Code of Conduct.
freebs is a new contributor. Be nice, and check out our Code of Conduct.
freebs is a new contributor. Be nice, and check out our Code of Conduct.
freebs is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f232681%2ftrying-to-sum-two-separate-columns-but-not-together-as-part-of-a-search-result%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why the
WHERE value = :total_value...? What is it you want to show? A small sample of rows with wanted output would help.– ypercubeᵀᴹ
yesterday
total_value I was trying to use a place holder for the SUM data to echo out to a line like I say I'm no guru on this stuff. just trying to get through it :)
– freebs
yesterday