开发者

Php/mySQL database for GUI

Just a general database design question - no programming, but a bit of problem solving I can't quite get my head around...

I have a set of pages for a GUI, w开发者_高级运维hich each contain a set of 'modules' - basically styled content boxes containing a few functions/information relevant to the page.

Both the pages and modules are instantiated as php objects before being rendered. I want the variables for these objects (title, content etc...) to be called from a database.

What I can't work out is how to store this data in a database. I have a table where each entry is a page, and a table where each entry is a module, but I can't work out how to store the data representing the modules that each page has, particularly considering the modules may be common to more than one page.

Nested tables would be the ideal answer, does mySQL allow this?


This sounds like a many-to-many relationship. You need a third 'linking' table. So, for instance, if you have the following tables:

CREATE TABLE pages (
  id INT(11) NOT NULL, 
  title VARCHAR(40), 
  PRIMARY KEY (id)
);
CREATE TABLE modules (
  id INT(11) NOT NULL, 
  title VARCHAR(40), 
  PRIMARY KEY (id)
);

You would create the third table like:

CREATE TABLE pages_modules (
  pid INT(11) NOT NULL, 
  mid INT(11) NOT NULL, 
  PRIMARY KEY(pid, mid)
)

From here you can add modules to different pages by creating an entry in this table for each page/module pair.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜