PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
talat3
Forum Newbie
Posts: 3 Joined: Thu Mar 18, 2004 5:08 pm
Contact:
Post
by talat3 » Thu Mar 18, 2004 5:08 pm
I made some functions as used below and inside of them they have connections to a mysql database and then at the end they return variables like so:
return $formattedpayment;
---------------------------------------------------
when I call the function from another script (including the inc.php script that the functions are in, of course):
$total_payments = paymentsmade("$Customer_ID");
$total_invoices = invoicesdue("$Customer_ID");
I can then echo their values I get 1080 for total_payments and 780 for total_invoices...
However, when I do this:
$totaldue = $total_invoices - $total_payments;
echo $totaldue;
-779 prints! What the heck is going on???
why is $total_invoices showing up as a 1 in this SIMPLE math problem instead of 1080???
Thanks for your help!
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Thu Mar 18, 2004 5:12 pm
make sure that both variables are of type integer. If your $total_invoices is a string substracting an integer from it will produce funny results...
$totaldue=(int)$total_invoices-(int)$total_payments;
should produce a better result.
talat3
Forum Newbie
Posts: 3 Joined: Thu Mar 18, 2004 5:08 pm
Contact:
Post
by talat3 » Thu Mar 18, 2004 5:19 pm
even with the (int) in there it's coming back with a -779!
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Thu Mar 18, 2004 5:29 pm
make sure that invoicesdue() returns a int and not a string
talat3
Forum Newbie
Posts: 3 Joined: Thu Mar 18, 2004 5:08 pm
Contact:
Post
by talat3 » Thu Mar 18, 2004 11:08 pm
it seems to have been a MySQL error, I deleted the entries that were not working and it decided to work correctly. Kinda strange!
Thanks though!