Tiny website hrlp

Page may contain affiliate links. Please see terms for details.
I have a website that has a couple of constants that appear on multiple pages (prices). It's all php. What's the most efficient way of displaying them but not having to change every page when the price changes?

Is it having each time they're displayed as a php script, Java, MySQL? I know a little but no expert so please keep it simples!

Thanks in advance.
 

BrynCP

Über Member
Location
Hull
If you don't want to get too technical, a quick and easy solution may be to create a new file, e.g. prices.php

Code:
<?PHP

$price1 = "20.00";
$price2 = "21.00";

?>

Then in your other PHP files:
Code:
<?PHP include('prices.php'); ?>

Buy A for <?= $price1 ?>

Buy B for <?= $price2 ?>
 
@User9609 correctly describes the right way to do this from scratch.

But for the situation as you have described, @BrynCP has the right answer. Get all the constants into one file, then include that file in all the other files. I'd copy everything to new directory (call it "staging"), make the changes and when it's all working again, copy it back. In fact, I'd get everything into source code control before touching a thing.
 
OP
OP
M

Markymark

Guest
@User9609 correctly describes the right way to do this from scratch.

But for the situation as you have described, @BrynCP has the right answer. Get all the constants into one file, then include that file in all the other files. I'd copy everything to new directory (call it "staging"), make the changes and when it's all working again, copy it back. In fact, I'd get everything into source code control before touching a thing.
Yes the one from @BrynCP looks the ticket.

I do have a MySQL for other things but seems excessive for this. The php variables looks quick and easy.

Thanks all
 
Top Bottom