Jump to content

[SOLVED] simple addition


Softkites

Recommended Posts

Hi all, I am sort of a newbie at this and I have been trying to find the answer through online tutorials but have not been able to find the stuff I want. That is why I came to the professionals and hope that one of you can help me. I just want to make a simple addition.

I have a page counter set up that plants the outcome to a txt file. The txt file has nothing but a number in it. Now I know how to print out that number by using either "include" or "require", but I want to use that number from the txt file in an addition. I have placed a simple code below to give you an idea to what I am after. I want to add last months total to what is going on right know, so the number in the txt file is variable but last months number of course isn't so we can just write that down.

 

Can anybody help me solve this?

 

 

<?php
$last_month = 243;
$index_file = "inc/index.txt"; //this is where the fault is but how??
$a = $last_month;
$b = $index_file;
$c = $a+$b;
echo 'Last month we had    ';echo $a ;echo '<br>';
echo 'So far this month we have    '; echo $b ;echo '<br>';
echo 'That is a temporary total of    '; echo $c ;

?>

 

Steady Breezes all

Softkites

Link to comment
https://forums.phpfreaks.com/topic/148087-solved-simple-addition/
Share on other sites

<?php
$last_month = 243;
$index_file = "inc/index.txt";
$a = $last_month;
$b = (int)file_get_contents($index_file);
$c = $a+$b;
echo 'Last month we had    ';echo $a ;echo '<br>';
echo 'So far this month we have    '; echo $b ;echo '<br>';
echo 'That is a temporary total of    '; echo $c ;

?>

<?php
$last_month = 243;
$index_file = "inc/index.txt";
$a = $last_month;
$b = (int)file_get_contents($index_file);
$c = $a+$b;
echo 'Last month we had    ';echo $a ;echo '<br>';
echo 'So far this month we have    '; echo $b ;echo '<br>';
echo 'That is a temporary total of    '; echo $c ;

?>

 

Boy, thanks for the fast reaction, That gave me this error:

 

Fatal error: Call to undefined function: file_get_contents() in c:\phpdev\www\....\totalplus.php on line 246

 

Sorry, it did work. Thank you so much, boy I should have come here yesterday.

 

Take care,

 

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.