Jump to content


Photo

creating pages from database


  • Please log in to reply
3 replies to this topic

#1 dtsdave

dtsdave
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 13 March 2006 - 07:19 PM

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.

#2 kamiza

kamiza
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 March 2006 - 11:03 PM

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:

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

Calling the function article1
which would be

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

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

#3 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 13 March 2006 - 11:52 PM

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

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

and consider this url..

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

and..

select * from articles where articleID = 1

catch my drift??

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#4 dtsdave

dtsdave
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 14 March 2006 - 05:49 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users