/    Sign up×
Community /Pin to ProfileBookmark

"Re-use" of php-pages

Hi there.

I’m running a PHP/MySQL-based site wich displays results and information for different types of sports. The site as it is, works great. But as the site is growing, I’m starting to realize that I might be doing some basic things wrong. I’ll try to explain my situation/problem:

For each sports arrangement, I’m creating a new folder with all the pages on the server. I’m also creating a new database in MySQL, so that the results can be stored for a long time. But I’ve realized that the only file that changes between the same sport, is the file wich defines the MySQL-parameters like database, ip-adress and so on (the file is called connect.php). So I’ve been thinking that uploading all the files several times is a bit too much, since almost every page is identically. If I want to edit the page for a specific sport, I have to manually enter every past sports arrangement to edit each page.

Now, I’ve been thinking that it would be great to upload every identical page to a folder. And for each sports arrangement, I want to upload only the connect.php-file, and maybe another file that points back to the correct sports page/folder. I hope you understand what I want… I’m not the best at explaining things 😮

So, is this possible? I’ve been unable to achieve it, but I find it very strange if this isn’t possible.

Thanks!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Jarrod1937Apr 18.2010 — Thats a better approach, but still horribly inefficient.

You really should instead be using a single template file, the same database, and all the same files. You can further enhance the design by using php includes. So for example, your page structure would be:

------------ products.php ---------------------------------

main.php - this is the file that will handle all universal functions, including the database connection.

template_top.php - you can create a .html template and have a template_top.php parse that template. This template parser will allow you to add in sections dynamically. To help with efficiency and ease of coding you can split the template into two halves, top and bottom, after template_top parses the template file, it will echo out the top of the template, then you have your...

Your page code

template_bottom.php - Then template bottom will echo out the bottom half of the template.
-----------------------------------------------------------



Then, for the database... you don't need to create a new database for each section, that is what tables are for. Even then i'd recommend a more complex database structure that incorporates all possible sports (all records sit together, but are differentiated by a sports id). This way you can easily expand the table structure to allow for as many sports as you want, and you have to do no work beyond creating a new sports id.

To use this type of system properly, you will then create a few files that match their use:

sports_main_page.php

categories.php

products.php

each of this will include the files and structure mentioned above.

If this seems too complicated, you may want to look around online for an existing template system to use, though a system like the one i am proposing only took me an hour or two, to implement myself when i did it for a client.
Copy linkTweet thisAlerts:
@erik89authorApr 18.2010 — Thanks a lot Jarrod1937. I've never looked into templates, but it looks that it easily can simplify a lot of things for me. So I'll start reading me up on that right away and take it from there. Do you have any specifically good pages?
Copy linkTweet thisAlerts:
@Jarrod1937Apr 18.2010 — Sorry, have no particular recommendations. Though you can easily google for, php template tutorial, or something like to get some info on the subject. Though, keep in mind that some template systems are designed for static content, which does not easily work with sites that are database generated. Try to find a template system, if you're going to use an existing one, that allows you to easily insert your dynamic content. Usually these type of template systems are thus built around the dynamic content, rather than the content built around the template, if that makes any sense ?
×

Success!

Help @erik89 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...