Can this be done in php?
This may be so dumb that you laugh but hopefully this can be done. In php I can easily get values from a mysql database. Forgive my improper terminology, but I can print the value of $value from row $row in table $table.
Okay. But I just want to throw together a simple easy thing for a friend and I don't even want to use a database because this project doesn't warrant the effort. So my question is, if I store values in different php files, each of which has $value = "whatever" in it, can I call these values for printing on another page? Like this...
print the value of $value from file1.php
print the value of $value from file2.php
Can I do this strictly in php files only or would I need to put it all in a database?
Mark Hensler posted this at 17:05 — 14th August 2003.
He has: 4,048 posts
Joined: Aug 2000
<?php
// file1.php
$value = \"this is file one.\";
?>
<?php
// index.php
include(\"file1.php\");
echo $value; // this is file one.
?>
fifeclub posted this at 18:14 — 14th August 2003.
He has: 688 posts
Joined: Feb 2001
Cool. Thanks.
Suzanne posted this at 19:39 — 14th August 2003.
She has: 5,507 posts
Joined: Feb 2000
Depending on what you're doing, Mike, this may not be a good way to go about it. Having text in .txt files that you then conditionally include on a page may work, however?
Also, if the information in the values is small, you could instead just have one file with all the values (and unique variable names) and require it.
fifeclub posted this at 04:26 — 16th August 2003.
He has: 688 posts
Joined: Feb 2001
Thanks. Works fine because it's reasonably small amount of data. I have one follow up question.
I've got 30 lines that I need to change each week. This is the way each looks. The file which contains the variable (person#.php) will remain but the variable I desire to print from that file will keep changing. It will become $variable_week2 and so forth
<?php
include \"/home/account/public_html/person1.php\"; print $variable_week1;
include \"/home/account/public_html/person2.php\"; print $variable_week1;
include \"/home/account/public_html/person3.php\"; print $variable_week1;
?>
Easy enough to alter each one but trying to be as lazy as I can, I thought it would be even better if I could change just one variable for the week and automatically change the variable for each of the 30 lines at once. But I don't know how to use a variable within a variable.
It doesn't work but I was trying $this_week ="1"; and then trying to get $this_week into where the number 1 currently is in the code from above, following $variable_week in each line. Is this even possible?
Mark Hensler posted this at 04:37 — 16th August 2003.
He has: 4,048 posts
Joined: Aug 2000
<?php
$this_week = 1;
include \"/home/account/public_html/person1.php\"; print ${'variable_week'.$this_week};
include \"/home/account/public_html/person2.php\"; print ${'variable_week'.$this_week};
include \"/home/account/public_html/person3.php\"; print ${'variable_week'.$this_week};
?>
<?php
for ($i=1; $i<=30; $i++) {
include \"/home/account/public_html/person$i.php\";
print $variable_week1;
}
?>
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.