Jump to content

Archived

This topic is now archived and is closed to further replies.

dtsdave

creating pages from database

Recommended Posts

Hello. I've read a book, searched the web, read articles, and scoured forums and still am stumped. I think I'm missing something fundamental and that's why I haven't been able to find the answers I'm looking for.

Basically, I'm trying to create pages from the data I've put into MySQL. For example, say I've got a database that stores article ids, titles and content. I want to create one template that will display the title of a given article and the content.

I know how to get the info into MySQL. My problem is how to create pages for individual articles. I want to be able to go to [a href=\"http://www.site.com/article1\" target=\"_blank\"]http://www.site.com/article1[/a] and it'll have a page with the title and content for article 1, [a href=\"http://www.site.com/article2\" target=\"_blank\"]http://www.site.com/article2[/a] and it'll have a page with the title and content for article 2, and so on. I know naming the URLs will probably be tricky and that's not my concern right now. I'm just trying to display different articles with just one template as opposed to writing a separate template for each article.

I hope I was clear in stating my problem. Any help would be greatly appreciated. Thank you very much in advance.

Share this post


Link to post
Share on other sites
Are you talking about Pagination or just dynamic pages

If talking about dynamic pages then something like this:
You can have
?article=#
EX: news.php?article=1, news.php?article=2

then when you call up the articles something like this:

[code]
switch($_GET['article']){
case '1':
article1();
break;
case '2':
article2();
break;
}
[/code]

Calling the function article1
which would be

[code]
function article1() {
//script to get article1 out of mysql
}
[/code]

Could even have just 1 function and then have that switch statement in the function and then have $_GET['article']'s value get article# out of mysql
But just giving an example
I'm pretty new at php too

Share this post


Link to post
Share on other sites
The approach I would take to solving this problem is to break it down into what needs to be accomplished:
[ol type=\'1\'][*]Design the back-end (database)[*]Design all objects / functions for retrieving data and information[*]Design a page that dynamically displays data based on URL[*]Design a Template (UI.. how it will look)[/ol]
With those items in mind, it's not hard to see what needs to be done.

Think of a sample table ARTICLES

[code]CREATE TABLE articles (
articleID int(3) not null,
title        varchar(20) not null,
text        longtext not null)
[/code]

and consider this url..

[code]http://www.domain.com/article.php?id=1[/code]

and..

[code]select * from articles where articleID = 1[/code]

catch my drift??

Share this post


Link to post
Share on other sites
kamiza and keeB, thank you very much for your posts! You've got me on the right track and have been a big help.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.