Include Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Include Function

Post 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
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post 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:
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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?
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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).
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Ok, I know how to add to databases. So how do I use the variables?
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

How do I set the values in the database as values for use in the page?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Post Reply