Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Include file with links to facilitate link changes?


ranma's Avatar
Member
0 0

Instead of having all your 'a' tags with all the links hardcoded, would it be practical include a file that has all addresses and whenever you need a link to just use the variable for the link?

as in a href='$home'


AldarHawk's Avatar
The Manager
0 0

Why not just use a database query to do this?


ranma's Avatar
Member
0 0

Because that would put a hellalot of pressure on the DB. And it's pointless to use a db for such a thing. I don't mean storing IDs for threads or such, I mean mostly static links such as the link to the home page or the link to the, say, about page. Using an include should save you some time.

I don't mean an include for something like a sidebar. I was asking this question originally because I'm making a website which has a changing bar.


ynori7's Avatar
Future Emperor of Earth
0 0

ranma wrote: Because that would put a hellalot of pressure on the DB. No it wouldn't. Not unless you've got 100 links that need to be loaded every time the user visits a page in your domain.

Alternatively, you could use XML and PHP's XML Parser. That way you could pair the link with the name you want to give it.


ranma's Avatar
Member
0 0

But why not just use includes?


p4plus2's Avatar
Member
0 0

ranma wrote: But why not just use includes?

You could, but sometimes the easy way is not the best way. I agree with the XML idea, it is flexible and specialized to its purpose. Using XML forces you to stick to a game plan, this means you won't be tempted to use any 'quick and easy hacks' in your include page for whatever reason. XML can also be held externally, which means if you have a second site they can share urls or you could have a site tag. With XML you would also be able to add more feature to your links, such as adding a tag that will contain styling information.


ranma's Avatar
Member
0 0

But what are the advantages of using a db?

Using includes seems like it would be more portable and need less setup.


ynori7's Avatar
Future Emperor of Earth
0 0

ranma wrote: But what are the advantages of using a db? Simplicity.

Using includes seems like it would be more portable and need less setup. Then use includes. It's your site, do what you want.


p4plus2's Avatar
Member
0 0

ranma wrote: But what are the advantages of using a db?

Using includes seems like it would be more portable and need less setup.

The advantages are mostly the same as XML, however with a DB you don't directly see the file and its 'out of the way' so to speak. PostgreSQL has some good query analysing tools to test speed and such. In a DB you also can sort entries by page they will be used on, thus a query with a WHERE can be used so not all the links must be loaded. Below is an example table which would provide some nice functionality, but change it to how you need.

CREATE TABLE `links` (
`location` varchar(100) NOT NULL,
`style` varchar(250) NOT NULL,
`page` varchar(50) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1

ranma's Avatar
Member
0 0

Okay. Thanks guys. And @ynori7, I'm just playing the part of the person against it so I can see the advantages of using the db method.