感谢回复。
抱歉我的英语不好。
我想我说得不清楚。
例如我的表格:
--
-- Table structure for table `posts`
--
CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL,
`title` varchar(100) NOT NULL,
`content` mediumtext
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `posts`
--
INSERT INTO `posts` (`id`, `title`, `content`) VALUES
(1, 'hello', 'hello how are you ?');
-- --------------------------------------------------------
--
-- Table structure for table `translates`
--
CREATE TABLE IF NOT EXISTS `translates` (
`id` int(11) NOT NULL,
`table` varchar(255) NOT NULL,
`key` int(11) NOT NULL,
`column` varchar(255) NOT NULL,
`lang` varchar(3) NOT NULL,
`translate` text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `translates`
--
INSERT INTO `translates` (`id`, `table`, `key`, `column`, `lang`, `translate`) VALUES
(1, 'posts', 1, 'title', 'es', 'Hola'),
(2, 'posts', 1, 'content', 'es', 'Hola, cómo estás?');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `posts`
--
ALTER TABLE `posts`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `translates`
--
ALTER TABLE `translates`
ADD PRIMARY KEY (`id`), ADD KEY `table` (`table`,`key`,`column`,`lang`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `posts`
--
ALTER TABLE `posts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table `translates`
--
ALTER TABLE `translates`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3;
以及我对获取翻译的查询
select `column`,`translate` from `translates` where `table` = 'posts' && (`column` = 'title' || `column` = 'content') && `key` = 1 && `lang` = 'es' #Spanish translate
为什么我用这种方式?
因为我以后可以添加新表,我不需要新的设计表或新的编程
这是个好主意?