GIDNetwork > Multipart Articles on GIDNetwork
« A basic Bash Script Multipart Articles on GIDNetwork, Part 2 »

Multipart Articles on GIDNetwork

by: admin - Jan 03, 2006

Yesterday I published a script I had written sometime ago, to handle multi-part articles or blogs here at One example of such a multipart article is the series of Python Tutorials written by Crystalattice.

If you follow that link, you will find the links connecting you to the other parts of the tutorial somewhere on the web page i.e.

  • Beginning Python Tutorial (Part 2)

  • Beginning Python Tutorial (Part 3)

  • Beginning Python Tutorial (Part 4)

  • Beginning Python Tutorial (Part 5)

  • Beginning Python Tutorial (Part 6)

  • Beginning Python Tutorial (Part 7)

  • Beginning Python Tutorial (Part 8)

Because I had never intended the "content management" script I wrote for this site to be handling multipart articles or stories, I had to add the feature to the script after the fact.

I am telling you this because there are probably much better ways to handle multipart articles on a web site but having explained my situation, you will understand why I chose to add the feature here the way I have.

The GIDNetwork Article DB Table Structure

The MySQL database table structure for all the articles found here looks something like this. I will just show you a couple of columns to keep things simple. The other_columns include article, create_date, author_id, and other relevant information about each story or article submitted and published.

Generic Code Example:

DB Tablename: articles
id  | title                              | other_columns
 1  | GIDTemplate ready                  | ...
 2  | GIDLogin almost ready              | ...
26  | Beginning Python Tutorial (Part 1) | ...
27  | Beginning Python Tutorial (Part 2) | ...
74  | Beginning Python Tutorial (Part 8) | ...

Multipart Article DB Table Structure

Without having to modify my existing script too much, I simply created a new database table, e.g. article_parts. It will just be a 2 column table:

Generic Code Example:

-- Table structure for table `article_parts`

DROP TABLE IF EXISTS `article_parts`;
CREATE TABLE IF NOT EXISTS `article_parts` (
  `articleid` int(10) unsigned NOT NULL default '0',
  `partid` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`articleid`,`partid`),
  UNIQUE KEY `partid` (`partid`),
  FOREIGN KEY (`articleid`) REFERENCES `articles` (`id`) ON DELETE CASCADE,
  FOREIGN KEY (`partid`) REFERENCES `articles` (`id`) ON DELETE CASCADE

As stated previously, there are just 2 columns inside this new table i.e. `articleid` and `partid`. The 2 main indices are:

  1. PRIMARY: `articleid` + `partid`

  2. UNIQUE: `partid`

The second UNIQUE key on `partid` is essential because we will be querying the table searching this index in our SQL statement as you will see later, in part 2.

Now that the table is ready, I simply add the multipart article ids and if I did it only for the Beginning Python Tutorial articles, it could end up looking like this:

Generic Code Example:

DB Tablename: article_parts
articleid | partid
26        | 26
26        | 27
26        | 40
26        | 55
26        | 67
26        | 68
26        | 69
26        | 74

In the next chapter, I will show you the custom PHP function I had to write to query the database table and include some lines of example code that I had to add to the web page generating script for the articles here.

Would you like to comment? This story has been viewed 10,932 times.
« A basic Bash Script Multipart Articles on GIDNetwork, Part 2 »


Copyright © GIDNetwork™ 2001 - 2018

Another website by J de Silva

Page generated in : 0.01427 sec.