I’ve been putting together a database to handle content produced for a site, however, thinking about the long-term, I’m unsure if I have the best system.
At present I’m using the routing method of passing everything via index.php which .htaccess routes as follows index.php?route=example/url (user sees http://www.domain.com/example/url)
At present the database is setup like below:
uid | title | content | category
--------------------------------------------------
/ | Home | aaa | 1
/example | Example | bbb | 2
/example/url | Example: URL | ccc | 2
Though I am not sure if this is the best approach, especially if I wanted to rename example to something – I’d have to rename each URL…
So I’ve also thought about the Nested Set method (such as http://www.phpclasses.org/package/2547-PHP-Manipulate-database-records-in-hierarchical-trees.html) though this would just show lots of different numbers in the database where I could access everything by it’s node. Example below;
node | left | right | name
--------------------------
1 | 1 | 6 | Home
2 | 2 | 5 | Example
3 | 3 | 4 | URL
Then I could use the node as the uid? But I’m unsure how I could translate http://www.domain.com/example/url to the uid equalling 3…
I already do have a category column in my database at the moment, to categorise the content, though I could potentially alter this.
I’m basically looking for suggestions about how to proceed, because as the site gets more content it will be harder to change the setup – so I want to ideally get this right from day one.
-
Which of the two is better for scalability?
-
If the second, how to translate the URL to the node?
-
Could I somehow combine both so that the original database stores the uid as the node number, then do a join of some sort to make the uid be a url (as in 1) – then ]
^ I think I’d prefer this (the third), but unsure how to do in MySQL exactly, with some other benefits:
- I could replace my category system with the parent node – which may be better
- I could also then in theory store the node ID within a stats system, rather than a URL
If anyone can give some help/suggestions – I’d be grateful!
The nested set model probably is a good choice here. That’d result in a table layout like (
id,left,rightare the fields required by the nested set model, the others contain the respective content):More details on how to perform a particular query can be found here.
However I would not perform the look up on the database but a simple array cache:
This cache can be build up very easy (though expensive) and queried very easy.
On a side note: i suspect you’re trying to model page content here. Maybe you should refactor you database structure then as this table would have two responsibilities (url->content mapping and content).