Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

News-Site kind of url

0 views
Skip to first unread message

frizzle

unread,
Dec 14, 2005, 6:51:30 AM12/14/05
to
Hi Group,

I'm builiding a sort of a news-site, with a mySQL backend.
Nowadays, i come across a lot of news-pages with the
title of the article in the URL. For example this one:
http://www.nieuwnieuws.nl/ (dutch in this case)

Anyway, every article seems to have it's own html-page.
I know that the page in my example actually has php-pages and
a mysql-db.

In my own site, i use htaccess to simulate directories and everything,
but what i wonder is how THIS system works.
If site.com/news/hot_news.html is converted to
site.com/news.php?article=hot_news,
Does this mean that the PHP looks in the DB "WHERE article =
'hot_news'" ?
Meaning it looks for a piece of text instead of an actual id?

Wouldn't it mean the queries would be extremely slow?

I hope my question is clear, since i don't exactly know how to explain.

Thanks, Frizzle.

Erwin Moller

unread,
Dec 14, 2005, 7:06:21 AM12/14/05
to
frizzle wrote:

> Hi Group,
>
> I'm builiding a sort of a news-site, with a mySQL backend.
> Nowadays, i come across a lot of news-pages with the
> title of the article in the URL. For example this one:
> http://www.nieuwnieuws.nl/ (dutch in this case)
>

Geeft niks. Mooie taal.

> Anyway, every article seems to have it's own html-page.
> I know that the page in my example actually has php-pages and
> a mysql-db.
>
> In my own site, i use htaccess to simulate directories and everything,
> but what i wonder is how THIS system works.
> If site.com/news/hot_news.html is converted to
> site.com/news.php?article=hot_news,

Probably yes.

> Does this mean that the PHP looks in the DB "WHERE article =
> 'hot_news'" ?

Maybe. Hard to say.
Maybe the hot_news is something special, like a collection of articles.


> Meaning it looks for a piece of text instead of an actual id?

I agree. A good databasedesigner/webappbuilder would avoid full text
substringsearch wherever possible.
But maybe the receiving script checks for special cases like 'hot_news' and
will respond accordingly.

For example: If it is an integer: get the article, if it is a special
string, do something else.


>
> Wouldn't it mean the queries would be extremely slow?
>
> I hope my question is clear, since i don't exactly know how to explain.
>
> Thanks, Frizzle.

google for mod_rewrite
I expect such a module is behind it.

Regards,
Erwin Moller

Henrik Hansen

unread,
Dec 14, 2005, 7:09:55 AM12/14/05
to
"frizzle" <phpfr...@gmail.com> writes:

> Hi Group,
>
> I'm builiding a sort of a news-site, with a mySQL backend.
> Nowadays, i come across a lot of news-pages with the
> title of the article in the URL. For example this one:
> http://www.nieuwnieuws.nl/ (dutch in this case)
>
> Anyway, every article seems to have it's own html-page.
> I know that the page in my example actually has php-pages and
> a mysql-db.
>
> In my own site, i use htaccess to simulate directories and everything,
> but what i wonder is how THIS system works.
> If site.com/news/hot_news.html is converted to
> site.com/news.php?article=hot_news,
> Does this mean that the PHP looks in the DB "WHERE article =
> 'hot_news'" ?
> Meaning it looks for a piece of text instead of an actual id?
>
> Wouldn't it mean the queries would be extremely slow?
>

could also be something like:

switch ($_GET["article"]) {
case "hot_news":
//do stuff
break;
}

if you see my point. I agree using text for the id is not the best
thing to to, but they could also be doing somekind of join with a
artucle type table like:

select *
from articles, article_types
where article_types.type_name = 'hot_news'
and articles.type = article_types.type

--
Henrik Hansen

frizzle

unread,
Dec 14, 2005, 7:32:47 AM12/14/05
to

Thank you both for your answer!
Maybe 'hot_news' wasn't that good of a choice.
I meant that as a name of an article, not as a type
of news. So i guess the second explanation with swicth/case
isn't appropriate here? Or am i missing out on something?

And what it comes to the mod_rewrite part, AFAIK this works
with set up grids to which an URL should comply.
Like site.com/news/78346_cool_article_over_here.html
becomes site.com/news.php?id=78346
(if you get what i mean)

I still can't imagine there is a full-text search query related to
this.
(Even if the url would be saved in an extra field, and use
SELECT WHERE url = $_GET['url'] )

Thanks.

Henrik Hansen

unread,
Dec 14, 2005, 8:03:13 AM12/14/05
to
"frizzle" <phpfr...@gmail.com> writes:

> Thank you both for your answer!
> Maybe 'hot_news' wasn't that good of a choice.
> I meant that as a name of an article, not as a type
> of news. So i guess the second explanation with swicth/case
> isn't appropriate here? Or am i missing out on something?
>

ah ok I get it, it's the title of the page.

I have seen solutions which simply write the whole page
structure on the server, as is, that's a fairly easy task too
and gives you nice urls. The only thing the pages would contain
was a page id (and a bit of handling code) which is used in the
sql tables.

--
Henrik Hansen

frizzle

unread,
Dec 14, 2005, 5:11:37 PM12/14/05
to
Hmm, i don't completely understand that.
You mean they actually create the files?

Greetings Frizzle.

NC

unread,
Dec 14, 2005, 6:08:45 PM12/14/05
to
frizzle wrote:
>
> what i wonder is how THIS system works.
> If site.com/news/hot_news.html is converted to
> site.com/news.php?article=hot_news,
> Does this mean that the PHP looks in the DB "WHERE article =
> 'hot_news'" ?
> Meaning it looks for a piece of text instead of an actual id?

First of all, it is entirely possible that HTML pages you are referring
to are in fact static. Some content management systems actually
separate writing, editing, and publication. An article can be
submitted by the author and stored in a database until the editor
approves its publication, at which point static HTML files are created
and publication's home page and RSS feeds are updated.

Now to your question. If you do decide to use mod_rewrite in the
above-described fashion, you can simply do something like this:

if (is_numeric($_GET['article'])) {
$id = (int) $_GET['article'];
$query = "SELECT * FROM articles WHERE id=$id";
// Execute the query and display the article...
}
else {
$search = $_GET['article'];
switch $search {
case 'hot_news':
$query = "SELECT * FROM articles ORDER BY id DESC LIMIT 5";
break;
// more case statements here...
}
// Execute the query and display the article headers/teasers...
}

Cheers,
NC

frizzle

unread,
Dec 14, 2005, 6:49:36 PM12/14/05
to

Thanks NC, but what i wonder in your first description of a system with
actual pages, how would you edit/update these?


And for your solution to my 'problem'; i meant how to handle DB-entries
if not reffered to them as ID's, but as actual topic names ...

Thanks. Frizzle.

Dikkie Dik

unread,
Dec 14, 2005, 6:59:37 PM12/14/05
to
I am not very familiar with Apache and htaccess options, but I think
some webservers can select a default (script) file by the directory,
even if more nonexisting subdirectories are given. You can then just
parse the REQUEST-URI to get the directory-style parameters.

Looking up a string is not that much trouble for a database. And there
are lots of possibilities to optimize it. The site could, for instance,
keep a relatively small table of "active" articles with name and ID. You
could look up the name in the small table quite fast, read the ID and
find the article by its ID from a much larger, more static, table.
On the other hand, special keywords like "latest news" could well be
filtered out in PHP and result in a query that requests articles sorted
by date.
It would not even be that hard to drive the entire article selection on
the news site by using just dates and categories. If your categories are
fixed, you could store them in some included PHP file instead of your
database if you really wanted to. But a categories table isn't that
large anyway, so there would be no need.

NC

unread,
Dec 14, 2005, 7:45:56 PM12/14/05
to
frizzle wrote:

> NC wrote:
> >
> > First of all, it is entirely possible that HTML pages you are referring
> > to are in fact static. Some content management systems actually
> > separate writing, editing, and publication. An article can be
> > submitted by the author and stored in a database until the editor
> > approves its publication, at which point static HTML files are created
> > and publication's home page and RSS feeds are updated.
>
> how would you edit/update these?

You wouldn't. You would edit the articles stored in the database and
then re-publish (overwrite old static HTML files with new ones).

> > Now to your question. If you do decide to use mod_rewrite in the
> > above-described fashion, you can simply do something like this:
> >
> > if (is_numeric($_GET['article'])) {
> > $id = (int) $_GET['article'];
> > $query = "SELECT * FROM articles WHERE id=$id";
> > // Execute the query and display the article...
> > }
> > else {
> > $search = $_GET['article'];
> > switch $search {
> > case 'hot_news':
> > $query = "SELECT * FROM articles ORDER BY id DESC LIMIT 5";
> > break;
> > // more case statements here...
> > }
> > // Execute the query and display the article headers/teasers...
> > }
>

> And for your solution to my 'problem'; i meant how to handle DB-entries
> if not reffered to them as ID's, but as actual topic names ...

This is exactly what the above does. If $_GET['article'] is a number,
it is interpreted as an article ID, and the script shows full text of
the article. If it is not, it is interpreted as a topic identifier,
and the script displays only headers and/or opening paragraphs and
links to full text. Topic 'hot_news', in particular, includes five
most recent articles...

Cheers,
NC

frizzle

unread,
Dec 15, 2005, 3:11:24 PM12/15/05
to

Thanks for al the replies!
I think Dikkie Dik convinced me of how to do it.
But NC (not to be a nag) but topics on the page in my example,
www.nieuwnieuws.nl,
can be commented. Wouldn't there be a bigger risk in rewriting the
pages then
insert new comments in a DB?

Thanks! Frizzle.

0 new messages