Jump to content

[SOLVED] Help with Running Total


Bifter

Recommended Posts

Hi All,

 

I'm not sure if this is possible however I would like to add the output of functions together, hence the running total. If this is not possible please can somebody suggest the correct way to do this before I have no hair left on my head!!! ???

 

The code I have created so far is:

<?php
/* Avaya - From Form*/
$LinesAnalogue = $_POST['LinesAnalogue'];
$LinesISDN2e = $_POST['LinesISDN2e'];
$LinesISDN30e = $_POST['LinesISDN30e'];
$DigitalExt = $_POST['DigitalExt'];
$AnalogueExt = $_POST['AnalogueExt'];
$Voicemail = $_POST['Voicemail'];
$BasicHand = $_POST['BasicHand'];
$GeneralHand = $_POST['GeneralHand'];
$ExecHand = $_POST['ExecHand'];

/* Main Unit */
$MainUnit = 406;

/* Line Cards */
$AnaLineCard = array(
               array('Card' => 'Analogue Card', 'Price' => '232'),
               array('Card' => 'ISDN2e Card', 'Price' => '275'),
               array('Card' => 'ISDN30 Card', 'Price' => '530')
               );
$ISDN2e = 275;
$ISDN30e = 530;

/* Extension Cards */
$DigitExt = 319;
$AnaExt =  145;

/* Voicemail */
$Voicemail =  500;

/* Handsets */
$LineISDN2e = 72;
$LineISDN30 =  152;
$finalAvaya = 218;

/* Extras */
$Instal = 400;
$Train =  400;

/* Main Unit */
function MainUnit ($MainUnit) {
global $MainUnit;
echo $MainUnit;
}
echo "Main Unit" . " = £";
echo MainUnit ( ) . "<br>";

/* Analogue Card */
function AnaLineTotal ($AnaLineCard,$LinesAnalogue) {
global $LinesAnalogue;
global $AnaLineCard;
if ($LinesAnalogue <= 0 ) {
  echo "Not Required" . "<br>";
  }
elseif ($LinesAnalogue <= 5 ) {
  echo $AnaLineCard['0']['Price'] . "<br>";
  }
elseif ($LinesAnalogue <= 8 ) {
  echo $AnaLineCard['0']['Price'] * 2 . "<br>";
  }
elseif ($LinesAnalogue <= 12 ) {
  echo $AnaLineCard['0']['Price'] * 3 . "<br>";
  }
}

echo $AnaLineCard['0']['Card'] . " = £";
echo AnaLineTotal ( ) . "<br>";

/* Running Total */
echo "Total = £";
echo MainUnit () + AnaLineTotal ();

?>

 

and this outputs like so:

 

Main Unit = £406

Analogue Card = £232

 

Total = £406232

0

 

Any help/advice would be much appreciated!!!

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/112007-solved-help-with-running-total/
Share on other sites

all your functions use echo

to get

echo MainUnit () + AnaLineTotal ();

to work the functions need to have a return instead so mainunit would look like

function MainUnit ($MainUnit) {
global $MainUnit;
return $MainUnit;
}

also you might want to change your DB password now  :)

 

Scott.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.