Page 1 of 1

Include Function

Posted: Mon May 30, 2005 2:02 pm
by Parody
I was wondering how to do this:

Have a list of values for use in a page
Be able to add another set of values using a page
Make sure that the values can be used in different pages
Have a value to display how many sets of values there are

Posted: Mon May 30, 2005 2:03 pm
by Parody
Sorry, I used the wrong topic name, my original topic changed. But I suppose I could use some form of the include function :oops:

Posted: Mon May 30, 2005 2:33 pm
by Skara
a bit vague... You mean something like a config file?

Code: Select all

//config.php
$config['name'] = "me";
$config['place'] = "here";
$config['age'] = 123;
#etc

//moreconfig.php
require 'config.php';
$config['occupation'] = "astronaut";
$config['something'] = 'e';
#etc

//anotherfile.php
require 'config.php';
# OR
require 'moreconfig.php';
...that something like you want?

Posted: Mon May 30, 2005 2:35 pm
by Parody
How do I add to the file without editing the code? I mean without having to open the code in an editor. So I can edit it through my site? With a form of some kind? :D

Posted: Mon May 30, 2005 2:41 pm
by Ambush Commander
Databases, I think, are what you are talking about.

Database = Persistent, static data

Generally, writing PHP with PHP is frowned upon, unless you're doing configuring (then it probably is the best way to set options without impacting performance).

Posted: Mon May 30, 2005 2:44 pm
by Parody
Ok, I know how to add to databases. So how do I use the variables?

Posted: Mon May 30, 2005 2:49 pm
by Skara
Ah, yeah. For something like that'd just use MySQL or something.
So how do I use the variables?
http://php.net/mysql

Posted: Mon May 30, 2005 2:52 pm
by Parody
How do I set the values in the database as values for use in the page?

Posted: Mon May 30, 2005 3:58 pm
by John Cartwright

Code: Select all

$result = "SELECT * FROM `config`";
$result = mysql_query($result) or die(mysql_error());
$config = mysql_fetch_assoc($result);

$max_pages = $config['max_pages'];
I don't really understand what you mean..
but another way to approach this is have an ini with set variables and access those variables through parse_ini() and edit the form file through fopen, fwrite, fread, and fclose or file_get_contents() and file_put_contents() if you have php5 installed.

I would recommend using a database though.