Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:16:26+00:00 2026-06-13T01:16:26+00:00

Below I have a lot of Adding and values being created with PHP. It

  • 0

Below I have a lot of Adding and values being created with PHP.

It all works fine! And it can be seen in action here: http://universitycompare.com

EXCEPT – the first set of PHP that has ‘$totalcost’ in it. I can’t seem to work out why my values created further below cannot be used to create a total.

Any opinions?

<?php
$totalcost = $totalcost2 + $totalcost3; 
$totalcost2 = $li444 + $tuitionTotal;
$totalcost3 = $li4 + $li44;
?>

<!-- WORKING OUT TOTAL TCE -->

<p>
<b class="TCE">
<?php echo $totalcost; ?>
<?php echo array_sum($a); ?>
</b> 
</p>

<!-- END OF WORKING OUT TOTAL TCE -->

<br /><br />
<h2>
Below is a a breakdown of the total cost of Education:
</h2>

<?php
$li2 = get_field('average_drinks_spenditure_per_night');
$li3 = ($li2 * 28) * 2.1;
$li4 = $li3 * 3;
?>

<div class="TCE">
<br />
<h2>Average spent on socialising</h2>
<ul class="TCE">
<li><span>Average drink cost</span>&nbsp;&nbsp;£<?php echo the_field('average_drink_price'); ?></li>
<li><span>Average drinks spenditure per night</span>&nbsp;&nbsp;£<?php echo $li2; ?></li>
<li><span>Average drinks spenditure for the year</span>&nbsp;&nbsp;£<?php echo $li3;?><!-- JAVA BIT --></li>
<li><span>Average drinks spenditure for 3 years</span>&nbsp;&nbsp;£<?php echo $li4;?><!-- JAVA BIT --></li>
</ul>

<?php
$li22 = (get_field('average_housing_costs_per_week') * 4 );
$li33 = $li22 * 12;
$li44 = $li33 * 3;
?>

<h2>Average spent on living costs</h2>
<ul class="TCE">
<li><span>Housing per week</span>&nbsp;&nbsp;£<?php echo the_field('average_housing_costs_per_week'); ?></li>
<li><span>Housing per month</span>&nbsp;&nbsp;£<?php echo $li22; ?></li>
<li><span>Housing per year</span>&nbsp;&nbsp;£<?php echo $li33; ?></li>
<li><span>Housing for 3 years</span>&nbsp;&nbsp;£<?php echo $li44; ?></li>
</ul>

<div class="clear"></div>   
<p><br /></p>

<?php
$li222 = (get_field('average_shopping_trip_price') * 2.25 );
$li333 = $li222 * 12;
$li444 = $li333 * 3;
?>

<h2>Average spent on food shopping</h2>
<ul class="TCE">
<li><span>Average shopping trip </span>&nbsp;&nbsp;£<?php echo the_field('average_shopping_trip_price'); ?></li>
<li><span>Average shopping for the month</span>&nbsp;&nbsp;£<?php echo $li222; ?></li>
<li><span>Average shopping for the year</span>&nbsp;&nbsp;£<?php echo $li333; ?></li>
<li><span>Average shopping for 3 years</span>&nbsp;&nbsp;£<?php echo $li444; ?></li>
</ul>

<?php
$tuitionClass = (get_field('tuition_fees') /28 );
$tuitionTotal = (get_field('tuition_fees') * 3 );
?>

<h2>Average spent on tuition</h2>
<ul class="TCE">
<li><span>Price per Week</span>&nbsp;&nbsp;£<?php echo $tuitionClass; ?></li>
<li><span>Average tuition fee</span>&nbsp;&nbsp;£<?php echo the_field('tuition_fees'); ?></li>
<li><span>Average tuition fee for 3 years</span>&nbsp;&nbsp;£<?php echo $tuitionTotal; ?></li>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:16:27+00:00Added an answer on June 13, 2026 at 1:16 am

    Finally worked it out as it seems I didn’t know defining totals before was not possible, some strange reason I thought it would relay it back, lesson learned!

    <?php
    // AVERAGE DRINK COSTS 
    $li2 = get_field('average_drinks_spenditure_per_night');
    $li3 = ($li2 * 28) * 2.1;
    $li4 = $li3 * 3;
    
    // HOUSING COSTS 
    $li22 = (get_field('average_housing_costs_per_week') * 4 );
    $li33 = $li22 * 12;
    $li44 = $li33 * 3;
    
    // SHOPPING COSTS 
    $li222 = (get_field('average_shopping_trip_price') * 2.25 );
    $li333 = $li222 * 12;
    $li444 = $li333 * 3;
    
    // TUITION FEES 
    $tuitionClass = (get_field('tuition_fees') /28 );
    $tuitionTotal = (get_field('tuition_fees') * 3 );
    
    // PHP TCE 
    $totalcost2 = $li444 + $tuitionTotal;
    $totalcost3 = $li4 + $li44;
    $totalcost = $totalcost2 + $totalcost3; 
    ?>
    

    This is what I used in the end and just put that before any of the values needed to echo’d.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a lot of helper classes for some reasons like below:
I have a array which contains values like this See below for script sample
I have a php mail script that works well except for one minor fact.
If any of the nested div s below have a length longer then an
Below I have a function that animates a div ( container ) either to
Below I have table - Company id name value year 1 IBM 10 2011
Below I have a line of code where it states which Session a user
Below I have written a sample program that I have written to learn about
below i have a code that runs in most of my simple programs ..
Below I have an application. Now on the previous page user types in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.