News Project Help!! How to load detailed article?

I’m working on a project for a news site. so I have an index page full of headlines. The problem comes when I have to load full article. Since I have not done this before so I am not sure what is the right way to handle this. What I am guessing is that I should create a dynamic page which should be initially empty and when the user clicks on a news headline on index page the empty page should retrieve title and detail from the database based on the id passed to this page. is this the right way? Any help would be great.

Yes you’d usually create a page that outputs the article title, text, etc. At the start of the pages code you fetch the correct article, ie based on a GET param you receive.

example

in the article listing you link to the articles like this: article.php?id=1

in article.php you fetch the article that has the id in $_GET[‘id’]
Remember to add a 404 if the id is invalid, and use prepared/parameterized queries :slight_smile:

thanks for replying :slight_smile:

what happens when I search for a news article on my site in google? how will that get loaded?

couldn’t understand the last line since I’m a beginner php programmer. What does it mean. thanks

Google will have cached the article?id=1 links so that should work as any other link

Thanks. You have helped me a lot.

I have a query for you today about tables. Since there are so many subsections in news like science etc. Should I create one table for news only or should I create separate for each section? With only one for news don’t you think it will become quite large?

It depends on how many millions of rows you want to set up your app for. Normally you don’t have to worry about scale, when a site/app has so much content you should also be further along business wise and will probably have changed half the code/db anyway.

Have one table for articles, one table for categories (sections) and then either set a category for each article, or have a join table if you want an article to be able to belong to multiple categories

Yes I have two tables. One for Categories and one for articles. I’m using category ID as a foreign key in the articles table.

Sponsor our Newsletter | Privacy Policy | Terms of Service