Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Your Email:

A Flexible Method of Storing Control Data

By Tony Marston
2006-08-29


A flexible approach

After encountering those disadvantages on more than one occasion I decided on a different and more flexible approach. Instead of a single record containing many values I have each value on its own record, which therefore results in many records. The trick is to store these values in separate records in the database, but to present them to the user in a single screen as if they were separate values on a single record. How is this possible? Read on and learn.

First, let us start with the database structure:

CREATE TABLE `mnu_control` (
`record_id` varchar(16) NOT NULL default '',
`field_id` varchar(32) NOT NULL default '',
`field_value` varchar(255) default NULL,
PRIMARY KEY (`record_id`,`field_id`)
);









Field IDDescription
RECORD_ID is used to group various records into logical sets. The same table could be
used by multiple applications, so by setting RECORD_ID to the application name
each application's data can be kept separate from the other, even if any
FIELD_IDs are the same.
FIELD_ID is the name of the field, unqualified, in upper case.
FIELD_VALUE is a string field as its holds any value in display format regardless of the interface definition (number, date, time, boolean, etc) of the source field on the screen.

Second, build a screen where these records can be displayed and modified:



As you can see this looks like a completely normal screen, which is the whole idea.

Tutorial Pages:
» Introduction
» A flexible approach
» Implementation
» From database to screen
» From screen to database
» Summary


 | Bookmark
Related Tutorials:
» Installing MySQL on Windows
» Implementing High Availability in MySQL
» Stored Procedures are EVIL
» MySQL Database Handling in PHP
» Exploring MySQL CURDATE and NOW. The Same But Different.
» Creating a PostgreSQL and MySQL driver