Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-25-2009, 08:51 AM PHP Math problem
blueocto's Avatar
Junior Talker

Posts: 3
Trades: 0
I have this snippet of code that needs to create an amount of money but it appears to be outputting the wrong calculation. Can anyone see where I am going wrong? I'm sure I'm missing character(s) of some sort... :surrender:

HTML Code:
£<?PHP echo number_format($_SESSION['order_total'] + $delivery_charge + ($_SESSION['guardsman_units'] * $guardsman_unit_cost), 0); ?>
Example - The order total + delivery charge + guardesman units x guardsman unit cost = £whatever
__________________
"I don’t take a p!ss without getting paid." - Harlan Ellison
blueocto is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-25-2009, 08:57 AM Re: PHP Math problem
Average Talker

Posts: 24
Trades: 0
Try to print $_SESSION variables. Maybe one of them is not integer.
__________________
+
Please login or register to view this content. Registration is FREE

eugen is offline
Reply With Quote
View Public Profile
 
Old 03-25-2009, 09:01 AM Re: PHP Math problem
blueocto's Avatar
Junior Talker

Posts: 3
Trades: 0
Nah checked that; its ok.

I forgot to mention that the total created, needs to be divided by 36; so what would I do to ensure that happens?
__________________
"I don’t take a p!ss without getting paid." - Harlan Ellison
blueocto is offline
Reply With Quote
View Public Profile
 
Old 03-25-2009, 12:18 PM Re: PHP Math problem
Average Talker

Posts: 15
Name: Declan Dowling
Trades: 0
You could try helping php out by defining the sessions as variables, and working out the $guardsman_total before adding it to the rest of the script.

I tried the code below, and all variables values such as 100, 50 ect and it worked fine.

PHP Code:
<?
$order_total 
$_SESSION['order_total'];
$guardsman_units $_SESSION['guardsman_units'];
$delivery_charge $delivery_charge// just an example, not needed if already defined
$guardsman_unit_cost $guardsman_unit_cost// just an example, not needed if already defined

$guardsman_total $guardsman_units $guardsman_unit_cost;
$total $delivery_charge $order_total $guardsman_total;

echo 
"&pound;".number_format($total)."";


?>
Try this^.

Last edited by Declan; 03-25-2009 at 12:20 PM..
Declan is offline
Reply With Quote
View Public Profile
 
Old 03-25-2009, 05:21 PM Re: PHP Math problem
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
This should help and take care of the dividing by 36, though I have no idea why you'd want to do that:

PHP Code:
£<?PHP echo number_format(((float)$_SESSION['order_total'] + $delivery_charge + ((float)$_SESSION['guardsman_units'] * $guardsman_unit_cost))/360); ?>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to PHP Math problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41936 seconds with 12 queries