Sum Values From Different Columns










0















I am having problem adding up the values in a column with php.
These values where sent from checkboxes and i want to count only the values that where checked from the unit column.
Here is my code:



<?php
$id = $_POST['course'];
foreach($id as $value)
{
//echo $value;
$query = " SELECT * FROM french WHERE id= $value ";
$result = mysql_query($query) or die('Error, query failed');
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$course = htmlspecialchars($row['course_name']);
$code = htmlspecialchars($row['course_code']);
$unit = $row['unit'];
$status = $row['status'];
?>









share|improve this question
























  • You don't mention what is wrong with your code..

    – Nelson
    Oct 13 '12 at 23:56











  • this is the code am trying to use to sum:

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 0:18












  • So, where are you using the SUM?

    – hjpotter92
    Oct 14 '12 at 0:44











  • I'm not sure if this is an error when you copied your code into this post, but you seem to have left out the closing brackets for both of the loops.

    – Lix
    Oct 14 '12 at 1:34











  • it was an error while posting

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 15:41















0















I am having problem adding up the values in a column with php.
These values where sent from checkboxes and i want to count only the values that where checked from the unit column.
Here is my code:



<?php
$id = $_POST['course'];
foreach($id as $value)
{
//echo $value;
$query = " SELECT * FROM french WHERE id= $value ";
$result = mysql_query($query) or die('Error, query failed');
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$course = htmlspecialchars($row['course_name']);
$code = htmlspecialchars($row['course_code']);
$unit = $row['unit'];
$status = $row['status'];
?>









share|improve this question
























  • You don't mention what is wrong with your code..

    – Nelson
    Oct 13 '12 at 23:56











  • this is the code am trying to use to sum:

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 0:18












  • So, where are you using the SUM?

    – hjpotter92
    Oct 14 '12 at 0:44











  • I'm not sure if this is an error when you copied your code into this post, but you seem to have left out the closing brackets for both of the loops.

    – Lix
    Oct 14 '12 at 1:34











  • it was an error while posting

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 15:41













0












0








0








I am having problem adding up the values in a column with php.
These values where sent from checkboxes and i want to count only the values that where checked from the unit column.
Here is my code:



<?php
$id = $_POST['course'];
foreach($id as $value)
{
//echo $value;
$query = " SELECT * FROM french WHERE id= $value ";
$result = mysql_query($query) or die('Error, query failed');
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$course = htmlspecialchars($row['course_name']);
$code = htmlspecialchars($row['course_code']);
$unit = $row['unit'];
$status = $row['status'];
?>









share|improve this question
















I am having problem adding up the values in a column with php.
These values where sent from checkboxes and i want to count only the values that where checked from the unit column.
Here is my code:



<?php
$id = $_POST['course'];
foreach($id as $value)
{
//echo $value;
$query = " SELECT * FROM french WHERE id= $value ";
$result = mysql_query($query) or die('Error, query failed');
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$course = htmlspecialchars($row['course_name']);
$code = htmlspecialchars($row['course_code']);
$unit = $row['unit'];
$status = $row['status'];
?>






php sum






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 5:03









Cœur

17.9k9107147




17.9k9107147










asked Oct 13 '12 at 23:52









Ehileboh Eddie Romeo BeatsEhileboh Eddie Romeo Beats

151




151












  • You don't mention what is wrong with your code..

    – Nelson
    Oct 13 '12 at 23:56











  • this is the code am trying to use to sum:

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 0:18












  • So, where are you using the SUM?

    – hjpotter92
    Oct 14 '12 at 0:44











  • I'm not sure if this is an error when you copied your code into this post, but you seem to have left out the closing brackets for both of the loops.

    – Lix
    Oct 14 '12 at 1:34











  • it was an error while posting

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 15:41

















  • You don't mention what is wrong with your code..

    – Nelson
    Oct 13 '12 at 23:56











  • this is the code am trying to use to sum:

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 0:18












  • So, where are you using the SUM?

    – hjpotter92
    Oct 14 '12 at 0:44











  • I'm not sure if this is an error when you copied your code into this post, but you seem to have left out the closing brackets for both of the loops.

    – Lix
    Oct 14 '12 at 1:34











  • it was an error while posting

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 15:41
















You don't mention what is wrong with your code..

– Nelson
Oct 13 '12 at 23:56





You don't mention what is wrong with your code..

– Nelson
Oct 13 '12 at 23:56













this is the code am trying to use to sum:

– Ehileboh Eddie Romeo Beats
Oct 14 '12 at 0:18






this is the code am trying to use to sum:

– Ehileboh Eddie Romeo Beats
Oct 14 '12 at 0:18














So, where are you using the SUM?

– hjpotter92
Oct 14 '12 at 0:44





So, where are you using the SUM?

– hjpotter92
Oct 14 '12 at 0:44













I'm not sure if this is an error when you copied your code into this post, but you seem to have left out the closing brackets for both of the loops.

– Lix
Oct 14 '12 at 1:34





I'm not sure if this is an error when you copied your code into this post, but you seem to have left out the closing brackets for both of the loops.

– Lix
Oct 14 '12 at 1:34













it was an error while posting

– Ehileboh Eddie Romeo Beats
Oct 14 '12 at 15:41





it was an error while posting

– Ehileboh Eddie Romeo Beats
Oct 14 '12 at 15:41












1 Answer
1






active

oldest

votes


















0














Are you trying like this? Getting form array of form checkboxs and checking on database via ID's?



HTML FORM



Check 1 <input type="checkbox" name="val" />
Check 2 <input type="checkbox" name="val" />


PHP RESULT



$val = $_POST['val'];
$count = count($val);
foreach ($val as $val_res)

$query = 'SELECT * FROM french WHERE id='.$val_res;






share|improve this answer























  • No. am designing a student E-Portal. During course registration the student is to select the course he want to register. what i want to do is to sum the unit of each course e.g math 2, eng 3 = 5.

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 1:50










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12878090%2fsum-values-from-different-columns%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Are you trying like this? Getting form array of form checkboxs and checking on database via ID's?



HTML FORM



Check 1 <input type="checkbox" name="val" />
Check 2 <input type="checkbox" name="val" />


PHP RESULT



$val = $_POST['val'];
$count = count($val);
foreach ($val as $val_res)

$query = 'SELECT * FROM french WHERE id='.$val_res;






share|improve this answer























  • No. am designing a student E-Portal. During course registration the student is to select the course he want to register. what i want to do is to sum the unit of each course e.g math 2, eng 3 = 5.

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 1:50















0














Are you trying like this? Getting form array of form checkboxs and checking on database via ID's?



HTML FORM



Check 1 <input type="checkbox" name="val" />
Check 2 <input type="checkbox" name="val" />


PHP RESULT



$val = $_POST['val'];
$count = count($val);
foreach ($val as $val_res)

$query = 'SELECT * FROM french WHERE id='.$val_res;






share|improve this answer























  • No. am designing a student E-Portal. During course registration the student is to select the course he want to register. what i want to do is to sum the unit of each course e.g math 2, eng 3 = 5.

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 1:50













0












0








0







Are you trying like this? Getting form array of form checkboxs and checking on database via ID's?



HTML FORM



Check 1 <input type="checkbox" name="val" />
Check 2 <input type="checkbox" name="val" />


PHP RESULT



$val = $_POST['val'];
$count = count($val);
foreach ($val as $val_res)

$query = 'SELECT * FROM french WHERE id='.$val_res;






share|improve this answer













Are you trying like this? Getting form array of form checkboxs and checking on database via ID's?



HTML FORM



Check 1 <input type="checkbox" name="val" />
Check 2 <input type="checkbox" name="val" />


PHP RESULT



$val = $_POST['val'];
$count = count($val);
foreach ($val as $val_res)

$query = 'SELECT * FROM french WHERE id='.$val_res;







share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 14 '12 at 1:22









Marin SagovacMarin Sagovac

3,05141648




3,05141648












  • No. am designing a student E-Portal. During course registration the student is to select the course he want to register. what i want to do is to sum the unit of each course e.g math 2, eng 3 = 5.

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 1:50

















  • No. am designing a student E-Portal. During course registration the student is to select the course he want to register. what i want to do is to sum the unit of each course e.g math 2, eng 3 = 5.

    – Ehileboh Eddie Romeo Beats
    Oct 14 '12 at 1:50
















No. am designing a student E-Portal. During course registration the student is to select the course he want to register. what i want to do is to sum the unit of each course e.g math 2, eng 3 = 5.

– Ehileboh Eddie Romeo Beats
Oct 14 '12 at 1:50





No. am designing a student E-Portal. During course registration the student is to select the course he want to register. what i want to do is to sum the unit of each course e.g math 2, eng 3 = 5.

– Ehileboh Eddie Romeo Beats
Oct 14 '12 at 1:50

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • 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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12878090%2fsum-values-from-different-columns%23new-answer', 'question_page');

);

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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo