473,378 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Calculating total amount per quater

Hi all
I need an idea on where to start when calculating a total amount betwee n two dates from a database like I want amount of money paid out from 30/03/2004 and 30/07/2004 ,but in the database these dates are not captured as they come they are mixed as some may come two years later to be captured. I have to go throught the database taking in those apropriate dates I need and add them up.

I belive I need to use a while loop and add the one I need and skip those I do not want and take the total at the end.

Thanks
Jun 7 '07 #1
9 2425
ronnil
134 Expert 100+
if you only want to retrieve rows in a certain interval of values i think all database engines have that compiled in their language

in MySQL you could use "SELECT * FROM table WHERE date_column > date_interval_start AND date_column < date_interval_end ORDER BY date_column ASC"

for more info about date functions in mysql visit:http://dev.mysql.com/doc/refman/4.1/...functions.html
for more info about the SELECT statement in mysql visit http://dev.mysql.com/doc/refman/4.1/en/select.html

this way your rows are also sorted by the date the transaction took place.
Jun 7 '07 #2
Thanks for the reply but now I need to use PHP and mysql to get the sum of the amounts on a particular quater, using the loop.
Jun 7 '07 #3
pbmods
5,821 Expert 4TB
Thanks for the reply but now I need to use PHP and mysql to get the sum of the amounts on a particular quater, using the loop.
You can limit your results using the WHERE clause in your MySQL query, which is perfectly accessible in PHP.

If you absolutely have to work with every single (unsorted) record in the database at once, and there's absolutely nothing you can do about it, you'll have to use strtotime to convert the dates into Unix timestamps.
Jun 7 '07 #4
Thanks
But I was just told that I can use a while loop to resolve this having if loops inside it to take what I need and skip those I do not need, I've never worked with a while loop I do not know where to start wi th that.
Jun 8 '07 #5
You can limit your results using the WHERE clause in your MySQL query, which is perfectly accessible in PHP.

If you absolutely have to work with every single (unsorted) record in the database at once, and there's absolutely nothing you can do about it, you'll have to use strtotime to convert the dates into Unix timestamps.
I have been trying to convert my date but I am comming up with more than what I have in my database now I am not sure what date is it returning and more.I dont clearly catch this strtotime can anyone pliz explian breifly how it works.I am trying to read about it also.
Jun 8 '07 #6
pbmods
5,821 Expert 4TB
I have been trying to convert my date but I am comming up with more than what I have in my database now I am not sure what date is it returning and more.
Let's have a look at the loop you're using now.

dont clearly catch this strtotime can anyone pliz explian breifly how it works.I am trying to read about it also.
strtotime takes in any string that describes a date. It can be a MySQL datetime ('2007-05-30 23:59:59'), full text date ('May 30, 2007 11:59:59 PM'), or even a fuzzy-text date ('Yesterday at 3 PM'). It returns a Unix timestamp that you can use to compare dates.
Jun 8 '07 #7
[PHP]
session_start();

$connection = mysql_connect("localhost", "root", "issasql");
$select_db = mysql_select_db("wca", $connection);

mysql_query("SELECT dateinjury,amount FROM invoice WHERE persal = '".$_COOKIE["Persal"]."'")or die(mysql_error());

//var = $total;
$dateinjury = strtotime ($_POST['date1']);

$dateinjury = strtotime ($_POST['date2']);

echo strtotime($_POST['date1']), "\n";

echo strtotime($_POST['date2']), "\n";
/*
while(strtotime ($_POST['date1']) < strtotime ($_POST['date2']))
{
if (strtotime($_POST['date1']) < strtotime ($_POST['date2']))
{

$query = ("SELECT sum(amount) FROM invoice WHERE dateinjury = '".$_POST['date2']."'")or die(mysql_error());
echo "Total Amount" .$query;
}
}*/
[/PHP]

Ok this is totally wrong but is what I am using to try to see what is comming up, even when empty there still is someting comming up.The while loop part is where am trying to get all dates between the two dates, and add up the amounts, anybody with a right way may help.
Thanx
Jun 11 '07 #8
Hi all
I do manage to get the sum of all the amounts and display it the amounts paid and out standing amount. Any bright idea I can use to only add amounts that are between two inputed dates. My date type in the database is DATE.

Thanks for any help offerd
Jun 14 '07 #9
Hi all

I changed my date to varchar in the database
[PHP]
$m1 = $_POST['m1'];
$d1 =$_POST['d1'];
$y1 = $_POST['y1'];
$date1 = $y1.$m1.$d1 ;
echo $date1."<br>";
$m2 = $_POST['m2'];
$d2 =$_POST['d2'];
$y2 = $_POST['y2'];

$date2 = $y2.$m2.$d2."<br>";
echo $date2;
if( $date2 < $date1 && $date2 > $date1)
{
//do the calculation

}
else if ($dateinjury > $date2)
{
echo "No";
}
[/PHP]

But it is still adding all the dates, I am not sure how to handle the dates between must be the only dates added.At some level it does work but messes up agin.

PLEASE HELP THIS TIME
Jun 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: | last post by:
I have an Access database used to track donor pledges. In it, there is a table that contains three fields for each donor: Gift_Amount, Gift_Per_Year, and Matching_Gift_Ratio. The following...
4
by: The Bit Bandit | last post by:
Hopefully someone can help me create a query that I'm having some trouble with. I have three tables: invoices, invoicedetails, invoicepayments The fields are: invoices -------- InvoiceNo
10
by: Howard Martin | last post by:
I have a form at http://www.develop.check.com.au/hh/order.html where an extended sub-total and then a grand total is calculated as soon as a quantity is input by a user. I would like to be able to...
2
by: MT | last post by:
Hi, I have an invoicing system using postgresql. Each time a customer makes a purchase, a new record is inserted into the "cart" table. The "cart" table, among other things, contains a customer_id...
5
by: steve | last post by:
Hi All Not sure if this is the right forum, but I need the formula for calculating the amount of Sales tax (GST) from the tax included price In Australia GST is 10% and the standard formula is...
2
by: fatimahtaher | last post by:
Hi, I am new to C# programming and my first assignment requires me to calculate total interest paid on a loan. The user will input the loan, the interest rate per month, and the monthly payment....
3
rcollins
by: rcollins | last post by:
I ahve a database that I put together to keep track of the office supplies. We input what has been purchased and what goes out. When I run a report, usually it is just for a month, but I have a...
11
by: charmeda103 | last post by:
i have to calculate a total amount of pounds for my program. i am getting each pound calculated but i have to add up all those pounds into one total. the problem is one of the total pounds is not...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.