D
D
do-do-go2015-11-23 12:34:11
PHP
do-do-go, 2015-11-23 12:34:11

Which option is better?

Hey! I am writing an application where you can create content types: blog, news, photos. The structure of mysql tables is as follows:
content - settings and urls of content types
content_name_of_content_type - materials for content types, their urls, etc.
I made it so that when you open blog/ or news/, it looks for the content table to see if there is such a thing, and using this url I display materials of the necessary content from the content_blog and content_news tables.
But here's the problem, I need to be able to create not only a content type, but just ordinary pages. /about /contact etc.
Decided to do this:
1) When creating a content type, choose that it is a page and do not create a content_name_content_type table, but just create an entry in the content table and also add a text field to it for the page content.
2) Make a separate table for the page pages and check if the input url is not in the content table, then check it in the page table and display it.
Please advise which option to choose?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Beloborodov, 2015-11-23
@kowap

DROP TABLE IF EXISTS `t_content`;

CREATE TABLE `t_content` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `type` enum('blog','news','page') DEFAULT NULL,
  `alias` varchar(255) DEFAULT NULL,
  `title` varchar(555) DEFAULT NULL,
  `content` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

LOCK TABLES `t_content` WRITE;
/*!40000 ALTER TABLE `t_content` DISABLE KEYS */;

INSERT INTO `t_content` (`id`, `type`, `alias`, `title`, `content`)
VALUES
  (1,'blog','eto_statia_bloga','Это статья блога','Контент'),
  (2,'news','eto_novost','Это новость','Текст новости'),
  (3,'page','kontacty','Контакты','Обычная страница, например с контактами');

/*!40000 ALTER TABLE `t_content` ENABLE KEYS */;
UNLOCK TABLES;

S
shagguboy, 2015-11-23
@shagguboy

will slow down if you check on the URL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question