Page 1 of 1

This has got to be the stupidest, most frustrating problem..

Posted: Thu Mar 18, 2004 5:08 pm
by talat3
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!

Posted: Thu Mar 18, 2004 5:12 pm
by patrikG
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.

Posted: Thu Mar 18, 2004 5:19 pm
by talat3
even with the (int) in there it's coming back with a -779!

Posted: Thu Mar 18, 2004 5:29 pm
by dull1554
make sure that invoicesdue() returns a int and not a string

Posted: Thu Mar 18, 2004 11:08 pm
by talat3
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!