Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,207,365 members, 7,998,729 topics. Date: Sunday, 10 November 2024 at 04:49 AM

Please Help Me Look At My Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please Help Me Look At My Code (1446 Views)

Please Help Look At My Code (what is wrong with my code ) / Help Me Look At This Small Problem / Android Java Programmers, Please Help Me Look Into This (2) (3) (4)

(1) (Reply) (Go Down)

Please Help Me Look At My Code by nicolas247(m): 4:53pm On Sep 13, 2015
Please I am still new to php so i need maximum help on this.
I have more than one table in my database with the same column.

I need to sum a column total_ded from all the tables by id.
currently the code is working but how to call it and sum by id from php script is my challenge.

Please any help is appreciated.


here is my code
$exe = mysql_query('SELECT (SELECT total_ded FROM february where Id=$id)
+ (SELECT total_ded FROM march where Id=$id)
+ (SELECT total_ded FROM april where Id=$id)
AS total');



//echo "<tr>";
echo "<div align='center' width='200'>" . mysql_result($exe, 0) . "</div>";
Re: Please Help Me Look At My Code by lekan008(m): 4:56pm On Sep 13, 2015
Try and search YouTube for tutorials on Php
Re: Please Help Me Look At My Code by nicolas247(m): 5:13pm On Sep 13, 2015
lekan008:
Try and search YouTube for tutorials on Php
thank you brother but i already did search a lot of tutorials but i cant seems to get past that.

if you know any tutorial that solve the problem i will appreciate

thanks
Re: Please Help Me Look At My Code by Grime: 9:02pm On Sep 13, 2015
Hello,

What do you mean by "sum by id"? Is the code expected to produce more than one result?

When you say it is working, what does it do in its current state?

This kind of thing can be achieved with a JOIN or one of its variants.
Re: Please Help Me Look At My Code by lekan008(m): 12:00am On Sep 14, 2015
nicolas247:

thank you brother but i already did search a lot of tutorials but i cant seems to get past that.

if you know any tutorial that solve the problem i will appreciate

thanks
I'm not a programmer but I can help you to search.
Re: Please Help Me Look At My Code by lekan008(m): 12:02am On Sep 14, 2015
lekan008:

I'm not a programmer but I can help you to search.
Find this links useful

https://www.youtube.com/watch?v=27dR_sLaM74
Re: Please Help Me Look At My Code by lekan008(m): 12:03am On Sep 14, 2015
Re: Please Help Me Look At My Code by DharkPoet(m): 12:47am On Sep 14, 2015
Your question is not precise, I don't exactly get what you want to achieve.
But try the below code.

<?php

//code to sum column_ded from tables January, February, March
//I hope this works, let me know if it doesn't and the actual error you get
//I didn't run this

//First, check for proper DB connection

$val1 = 0;
$val2 = 0;
$val3 = 0;

$query_tbl1 = "SELECT (SELECT total_ded FROM february where Id=$id);";
$query_tbl2 = "SELECT total_ded FROM march where Id=$id";
$query_tbl3 .= "SELECT total_ded FROM april where Id=$id";

$get_total_ded1 = $mysql_query($query_tbl);
$get_total_ded2 = $mysql_query($query_tbl);
$get_total_ded3 = $mysql_query($query_tbl);

while($row = $mysql_fetch_assoc($get_total_ded1)) {
$val1 += $row["total_ded1"];
}

while($row = $mysql_fetch_assoc($get_total_ded2)) {
$val2 += $row["total_ded2"];
}

while($row = $mysql_fetch_assoc($get_total_ded3)) {
$val3 += $row["total_ded3"];
}

$total = $val1 + $val2 + $val3;

echo "<div align='center' width='200'>" . $total . "</div>";
?>
Re: Please Help Me Look At My Code by nicolas247(m): 11:29pm On Sep 20, 2015
thank you my brother
for the code you wrote i got this error "Fatal error: Function name must be a string in C:\xampp\htdocs\sel.php on line 84"

How ever, i want to say the function i wrote is working fine. all i just need is a form script that will call the function. some thing like session $id or any other method possible.

ones again, thank you

DharkPoet:
Your question is not precise, I don't exactly get what you want to achieve.
But try the below code.

<?php

//code to sum column_ded from tables January, February, March
//I hope this works, let me know if it doesn't and the actual error you get
//I didn't run this

//First, check for proper DB connection

$val1 = 0;
$val2 = 0;
$val3 = 0;

$query_tbl1 = "SELECT (SELECT total_ded FROM february where Id=$id);";
$query_tbl2 = "SELECT total_ded FROM march where Id=$id";
$query_tbl3 .= "SELECT total_ded FROM april where Id=$id";

$get_total_ded1 = $mysql_query($query_tbl);
$get_total_ded2 = $mysql_query($query_tbl);
$get_total_ded3 = $mysql_query($query_tbl);

while($row = $mysql_fetch_assoc($get_total_ded1)) {
$val1 += $row["total_ded1"];
}

while($row = $mysql_fetch_assoc($get_total_ded2)) {
$val2 += $row["total_ded2"];
}

while($row = $mysql_fetch_assoc($get_total_ded3)) {
$val3 += $row["total_ded3"];
}

$total = $val1 + $val2 + $val3;

echo "<div align='center' width='200'>" . $total . "</div>";
?>
Re: Please Help Me Look At My Code by nicolas247(m): 12:14pm On Oct 13, 2015
Problem not solved

Better Explanation for this in screen shot
On the screen shot is my tables and columns

What i need is to
sum a column (total_ded) from all the tables together per row meaning per id

at the moment this function is working just fine

after DB connection


$exe =("SELECT (SELECT total_ded FROM february where memberId=46)
+ (SELECT total_ded FROM march where memberId=46)
+ (SELECT total_ded FROM april where memberId=46)
AS total"wink;
$result = mysql_query($exe, $dbhandle);

//echo "<tr>";
echo "<div align='center' width='200'>" . mysql_result($result, 0) . "</div>";

What I need
First i need to replace thoese memberid with string that will pass the id
i need an input box where i can type the id and a script that will call the function work that is all i need

Note:
what am trying to do is to have each users have access to their information and at the same time the tables should sum up for a particular column which is total_ded.

Please all help is highly appreciated

(1) (Reply)

Who Is The Best Programmer? / Get Started With Laravel 5 – Tutsplus / Frontend Devloper/designer Needed

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 21
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.