September 13th, 2000, 10:48 AM
I am making a website to help myself maintain accounts, staff members, IP ranges, and usernames for multiple vendors. Right now I have 16 tables in MySQL for storing this information. I also have a admin page to edit these tables and a quest page that allows only viewing of these tables.
How should I organize my php files, scripts, functions and other files to help me maintain the increasing amount of code. For example, each table has a function for delete, insert, update, validate, view etc.
The ever increasing number of files and functions is creating a burden. How can I possibly organize these files. Should I be using one file per table, put all files in a directory for each file and use an include statement to include them. How does everybody handle this.
Thanks for your suggestions.
September 13th, 2000, 01:29 PM
Personally, if a single file is going to do lots of functions, I'd just make one file and vary what it does by passing arguments with the GET method. So for example....
<a href="table.php3?cmd=delete&table=ips">Click here to delete from the IP's table</a>
This way, you just change all the SQL queries inside the file to point to $table instead of the table name. Pass the actual table name to the file each time you call it. Do the same for the insert, update, validate etc..
Hope this helps,
September 13th, 2000, 06:39 PM
I suppose you could also create a file with all your functions and then use
to get access to the functions in all your php files. Then pass different arguments to the functions to act on different tables.
September 14th, 2000, 08:10 PM
I usually go for the functionality approach without getting too anal.
if you've a load of functions for - say - staff, create a file called staff functions.inc and include this for all the staff pages. Pull all DB functions into one file, all html into another etc..
if - as you say - you've got a load of functions for add/edit/delete (which is pretty standard for any web based app) you might thing about making these functions generic if possible. A good way to do this is use the mysql_feild_name et al, functions. You could then make generic functions for the addition/deletion etc of data from any table and just pass the table name in.
Personally I don't like this apporach as the code starts getting un-readable IMO.