Labels

Showing posts with label PHP and MySQL. Show all posts
Showing posts with label PHP and MySQL. Show all posts

Wednesday, May 25, 2011

Blog Program File

Before we make blog program, I want to introduce files and sources. I will mention simple explanation with file name.

1. util.php
- configuration file in which functions that are used by sources are saved.
2. config.php
- Variables are saved for connecting with database.
3. global.js
- javascript files that are used by all pages.
4. blog.js
- javascript files related with blog
5. blog_main.php
- blog index main file
6. blog_create_form.php
- configuration file for creating a blog
7. blog_create_post.php
- create a blog based on a input form
8. blog_mng_form.php
- manage basic information of blog
9. blog_mng_post.php
- processing contents that are written in form
10. blog_profile
- show personal user information
11. blog_brd_mng.php
- categorize blogs that are registered
12. blog_brd_write.php
- register and modify blog that are registered
13. blog_brd_write_post.php
- processing blog contents that is written in blog category form
14. blog_write.php
- write a blog
15. blog_view.php
- view a blog
16. blog_edit.php
- edit a blog
17. blog_list.php
- view list of blogs
18. blog_tlist.php
- view all list of blogs
19. blog_write_manager.php
- Process writing, editing and removing a blog
20. blog_memo_manager.php
- Write and remove comments
21. show_image.php
- Show image if there are image files that are attached.
22. img_del.php
- Remove only attached files
23. left_menu.php
- left part of page
24. blog_main_top.html
- top part of page
25. blog_main_bt.html
- bottom part of page

Useful SQL Query

- Create Database
CREATE DATABASE database_name;

- Create Table
CREATE TABLE table_name(
column_name1 type(length) option,
column_name2 type(length) option,
.
.
);

- Insert data into table
INSERT INTO table_name (column_name1, column_name2, ...) VALUES ('value1', 'value2',...);

- Get Data
SELECT columns FROM table_name;
We can add other columns or * instead of using a column to get more data.


Create Data Base Table for a blog

When we create tables in database for saving data, we should use SQL command and syntax as below.

Syntax for creating database table
CREATE TABLE Table_Name(
Column Column_Type Optioin,
Column Column_Type Optioin,
.
.
);

Now that we have learned how to create tables in a database, Let's create tables for a blog program. You can use any other tools to create and manage tables in a database, such as MySQL Admin or NetBeans. Of course, MySQL or other DBMS should be installed correctly before we create a database and tables.
1. Member Table
- Information of member will be saved in this table.

-SQL Statements
CREATE TABLE member(
seq_num int(11) NOT NULL auto_increment,
id varchar(10) NOT NULL,
passwd varchar(10) NOT NULL,
email varchar(50) NOT NULL,
name varchar(20) NOT NULL,
phone varchar(13) NOT NULL,
reg_date datetime,
PRIMARY KEY(seq_num),
KEY id(id)
);


2. Blog List Table
- If someone register and create blog, ID, name, blog name, blog contents will be saved in this table.

-SQL statements

CREATE TABLE blog_list(
bnum int(11) NOT NULL auto_increment,
user_id varchar(12) NOT NULL,
nick_name varchar(50) NOT NULL,
blog_name varchar(100) NOT NULL,
blog_cont varchar(255),
blog_cdate date,
PRIMARY KEY(bnum),
KEY user_id_idx(user_id)
);
3. Blog_info table
- Image of blog name, profile, Information about color and all information about blog will be saved in this table except for information about blog in blog_list table

- SQL Statements
CREATE TABLE blog_info(
inum int(11) NOT NULL auto_increment,
user_id varchar(12) NOT NULL,
blog_logo char(1) DEFAULT 'N' NOT NULL,
blog_logo_ty varchar(5),
my_profile varchar(255),
title_bytype char(1) DEFAULT '1' NOT NULL,
title_bgcolor varchar(1),
title_bgimg char(1) DEFAULT 'N' NOT NULL,
title_bgimg_ty varchar(5),
box_bgcolor varchar(10),
main_img char(1) DEFAULT 'N' NOT NULL,
main_img_ty_ varchar(5),
main_text text,
main_text_bt text,
view_chk char(1) DEFAULT 'Y' NOT NULL,
PRIMARY KEY(inum)
);

4. Blog category table
- Blogs that users wrote are categorized and saved in this table.
Also, privilege to read or comment will be saved in this table.

- SQL Statements
CREATE TABLE blog_brd_list(
num int(11) NOT NULL auto_increment,
user_id varchar(12) NOT NULL,
brd_title varchar(50),
brd_pow_1 char(1) DEFAULT '3' NOT NULL,
brd_pow_2 char(2) DEFAULT '3' NOT NULL,
brd_wdate date DEFAULT '0000-00-00' NOT NULL,
PRIMARY KEY(num),
KEY user_id_idx(user_id)
);

5. blog Counter Table
- The number of people who visit a blog will be saved in this table.
- SQL Statements
CREATE TABLE blog_visit_count(
vnum int(11) NOT NULL auto_increment,
user_id varchar(12) NOT NULL,
visit_date varchar(8) NOT NULL,
visit_count int(8) DEFAULT '0' NOT NULL,
PRIMARY KEY(vnum),
KEY user_id(user_id),
KEY visit_date(visit_date)
);
6. The table for saving visitors of blog
- Users who visit a blog will be saved in this table.

- SQL Statements
CREATE TABLE blog_visit_member(
mnum int(11) NOT NULL auto_increment,
user_id varchar(12) NOT NULL,
visit_data varchar(8) NOT NULL,
visit_id varchar(12) NOT NULL,
PRIMARY KEY(mnum),
KEY user_id(user_id),
KEY visit_id(visit_id)
);

7. Blog information table for each user
- Basic information for each user will be saved in this table
The table will be created during execution dynamically

- SQL statements
CREATE TABLE bg_user id_t(
num int(6) NOT NULL auto_increment,
brd_list_fk int(11) DEFAULT '0' NOT NULL,
id_fk varchar(12) NOT NULL,
name varchar(30) NOT NULL,
title varchar(200) NOT NULL,
blog_img1 varchar(50),
contents_1 text,
blog_img2 varchar(50),
contents_2 text,
blog_img3 varchar(50),
contents_3 text,
comm_chk char(1) DEFAULT 'Y' NOT NULL,
wdate varchar(8) NOT NULL,
PRIMARY KEY(num)
);

8. The table for saving comments of blog
- All comments of blog will be saved in this table for each user.
This table will be created during execution dynamically

-SQL statements
CREATE TABLE bg_user id_ct(
cnum int(6) NOT NULL auto_increment,
num_fk int(11) DEFAULT '0' NOT NULL,
id_fk varchar(12) NOT NULL,
memo text NOT NULL,
cdate varchar(8) NOT NULL,
PRIMARY KEY(cnum)
);


Friday, May 13, 2011

Blog Program with PHP and MySQL- 1

A blog is a type of website or part of a website. We can upload news, text, images. links to ohter blog, web pages, or anything we want.
Since today, I will make a blog program using PHP and MySQL. I hope this article will be very helpful for people who want to learn web programming using PHP and MySQL

First of all, I want to show structured view of the blog program. It shows how all files for the blog program are inter-related. This structured view is categorized as create blog, navigate blog, and manage contents and blog.