Forum Moderators: coopster
My problem is mainly to do with the linking system and how pages are linked together. The look of the url which I want to attain is like SearchEngineWatch's
http: //searchenginewatch.com/facts/article.php/2155971
now I assume that this uses mod_rewrite, but anyway I'm not concerned with that at the moment.
So does the above site just have one .php file for all its articles and when the page is given an article id via the url, it will then grab that article from the database and insert it into that page?
If I'm correct, what is the php/sql code which grabs the article id?
eg SELECT * FROM table WHERE id=2155971
If I'm not on the right track please tell me....
My issue now is one of identifying pages. How do you folks link to pages within your sites. I'm thinking "okay I need to link to that page about widgets, but which article number is that?" Do I then have to through the database and physically find it? It's just i currently use Dreamweaver where I can see the physical html files to link to them. I'm thinking that it will be a bit more difficult to manage if I only have the one physical file, i.e. article.php
So basically I just need some clarification on the whys and wherefores of 'how to link' on php/mysql web site please.
Thanks!
ps I can find plenty of site on the web that tell you about inserting content from databases, but not actually creating an article based website.
mod_rewriteyou'll want to use - it will 'translate' a url like:
dir/4567
dir/script.php?id=4567
$_GET['id'].
How do you make these urls?
You need to have a query like:
$query = SELECT id, title FROM table WHERE (here your selection criteria, and limit)
$result = mysql_query($query);or if you have more info you need, like an article's 'teaser' or prologue, you add this to your query (
while($info = mysql_fetch_assoc($query)) {
echo "\n".'<br /><a href="dir/'.$info['id'].'">'.$info['title'].'</a>';
}
SELECT id, title, prologue) and to the HTML in the echo line in the right place.
These links won't work until you have
mod_rewritein place.
If you use
SELECT *, the query will just grab all fields in that row and you get your $info array with all those fields as the corresponding keys (i.e., the part between brackets) - which is ok, but is a little less efficient. If you worry about speed, better then to designate actually what you want to select.
If I'm not on the right track please tell me....
Oh you're on the right track.
What is typically done is to have a table in your database named something like articles. You'd set up some basic fields like
ID
title
author (this might be another id field that will join with an author table)
date
article
You really don't have to worry to much about the id number. When you make a list of the articles you can make the titles into links with the id number built in as a GET variable.
pseudo code:
select id, title from articles
<a href="article.php?id=$id>$title</a>
Make sense?
Tim
If a website uses the same template throughout, is it realistic to use the same parent file for every page?
eg.
article.php?id=343
Also I think that this is the time to take a closer look at mod_rewrite and my urls.
Although article.php/343 would be ok. I would prefer something more like article.php/my-keyword
Where in the database do you advise it gets the my-keyword part of the string? How does it do it?