Forum Moderators: coopster

Message Too Old, No Replies

Help with db creation and dynamic pages

simple stuff i think

         

webstudio

3:18 am on Aug 1, 2003 (gmt 0)

10+ Year Member



Hi,

I have implemented some simple PHP (secure pages for users, creating accounts) with the inclusion of a mySQL DB.

Something i really want to do is have the content of my site (just text used on pages) to come from a DB? i know this can be done using PHP/mySQL, but i need some direction in terms of table creation and dynamic content creation in the site itself.

any help is appreciated

Regards,
webstudio

moltar

4:11 am on Aug 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Depends how you want your page to be set up.

Here is an example for pages with articles.

You can make your database like this:


CREATE TABLE articles (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
name TINYTEXT NOT NULL,
title TINYTEXT,
content TEXT NOT NULL,
PRIMARY KEY (id)
)

id - easier to manipulate table internaly. And always good to have an auto incrementing field.

name - name of the article to use in the path (explained later)

title - title or the article (page)

content - text of the article.

You should write a script which will read "name" from the database. You can do it either by passing values to the script using GET (/articles.php?name=article_about_widgets) or you can make it more usable and write a little .htaccess file to use mod_rewrite to imitate folders for each article. Then it will look like this: /articles/article_about_widgets/. The second way is better. It looks more appealing to search engines and most importand it's user friendly.

After script gets the name of the article you should fetch it from the database and display it to the screen. Make sure your article names are unique.

You can always make it a little more complex by adding some extra table columns. Such as date published, author's name, short description, etc...

Hope this helps.