FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Perform maths based on a number in a text file
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Perform maths based on a number in a text file [message #183807 is a reply to message #183800] Wed, 20 November 2013 16:20 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 11/20/2013 6:50 AM, drkirkby(at)gmail(dot)com wrote:
> On Monday, 18 November 2013 13:19:50 UTC, The Natural Philosopher wrote:
>
>> I would strongly recommend using a database: setting that up is a bit of
>>
>> a faff, but once set up it provides the sort of 'update by one screen,
>>
>> read buy many others' sort of access that you need. And wont need any
>>
>> file level parsing - you will get your numbers as an array from a Mysql
>>
>> type query.
>>
>>
>>
>> You can even embed the mathematics in the query instead of doing it on
>>
>> PHP, if you want.
>>
>>
>>
>> But all this assumes you are willing to knuckle down and learn basic
>>
>> SQL, mysql administration, and how to set up web forms and the like.
>>
>>
>>
>> If you are as you sound, a relative newcomer, this is a few weeks work :-(
>
> Hi,
> thank you for your thoughs. To be honest, I'm not over keen on using a database. I'm not a web designer, but an engineer trying to get data about his product on a web page. Maybe the constants will be updated in the future, but perhaps they never will. It is certainly not something I expect to do on a regular basis. The idea of spending 3 days working on this does not attract me.
>
> To answer the question asked by someone else about how the constants will get updated. It will be me doing it manually - no program will update them. Maybe file_get_contents will do what I want.
>
> Dave
>

If they're only going to be updated very rarely, and done so manually, I
would just stick them in a .php file as defined constants, i.e.

# File constants.php
<?php
define ('CONST1', 42);
define ('CONST2', 53);
.... etc.
?>

Then in the scripts where you need the constants, use:

# File script1.php

<?php
require_once('constants.php');

$value1 = CONST1 * 3; // 126
$value2 = CONST2 + 5; // 58

?>

The advantage of using constants is that a script cannot change them.

P.S. For personal preferences, I place all files like this outside of
the websites DOCUMENT_ROOT directory and access them relative to
DOCUMENT_ROOT. For instance, if my DOCUMENT_ROOT directory is

/var/www/mysite/html

I would place it as

/var/www/mysite/constants.php

then access them everywhere with

require_once($_SERVER['DOCUMENT_ROOT'] . '/constants.php');

This has three advantages - it prevents the file from being accessed
directly from the web (not a real concern in this case), it keeps
included (only) scripts from cluttering up your directories with
web-accessible files, and keeps the include code the same for any
script, no matter where in your website directory.

The only real downside is you must update the file locally and upload it
to the server or ssh into the server and edit the file there. (You
could build a web page to modify the script - but if it isn't going to
be changed often, why bother?).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: array search part 2
Next Topic: What do you think about this book on API ?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 09:46:13 GMT 2024

Total time taken to generate the page: 0.04277 seconds