1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Rep Power
    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.
  2. #2
  3. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    London, UK
    Rep Power
    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,

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    London, England
    Rep Power
    I suppose you could also create a file with all your functions and then use

    include "functions.php"

    to get access to the functions in all your php files. Then pass different arguments to the functions to act on different tables.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Rep Power
    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.



Similar Threads

  1. Replies: 2
    Last Post: August 18th, 2004, 11:45 PM
  2. Replies: 3
    Last Post: February 11th, 2004, 02:33 PM
  3. functions slowing code
    By dave2k in forum PHP Development
    Replies: 5
    Last Post: February 7th, 2004, 07:40 PM
  4. Ensuring a file's code doesn't cause error in another.
    By Jason Doucette in forum C Programming
    Replies: 0
    Last Post: February 6th, 2004, 01:51 PM
  5. vb code error combo box
    By xyfix in forum Visual Basic Programming
    Replies: 15
    Last Post: January 27th, 2004, 10:04 AM

IMN logo majestic logo threadwatch logo seochat tools logo