我有以下表格:
CREATE TABLE IF NOT EXISTS `mod_music_periods` (
`id` int(1) NOT NULL AUTO_INCREMENT,
`the_in` varchar(4) NOT NULL,
`period` varchar(4) NOT NULL,
`priority` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `period` (`period`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
CREATE TABLE IF NOT EXISTS `mod_music_category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` varchar(250) NOT NULL,
`teaser` text,
`priority` int(11) NOT NULL DEFAULT '0',
`style` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `mod_music_entries` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE latin1_general_ci,
`teaser` text COLLATE latin1_general_ci,
`description` text COLLATE latin1_general_ci,
`song_yr` varchar(4) COLLATE latin1_general_ci DEFAULT NULL,
`song_name` varchar(250) COLLATE latin1_general_ci DEFAULT NULL,
`photo` text COLLATE latin1_general_ci,
`active` enum('1','0') COLLATE latin1_general_ci NOT NULL DEFAULT '0',
`priority` int(5) DEFAULT NULL,
`period_id` char(150) COLLATE latin1_general_ci DEFAULT NULL,
`category_id` char(150) COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=21 ;
保存到mod_music_entries时,我们允许条目/记录包含多个“period_id”和“category_id”。
“mod_music_entries.period_id”字段使用包含在“b”和“e”字符加上“/ n”的mod_music_periods.id字段。例如b1e / n b2e / n b3e / n .. e.t.c
“mod_music_entries.category_id”字段使用以“b”和“e”字符加上“/ n”括起来的mod_music_category.id字段。例如b1e / n b2e / n b3e / n .. e.t.c
我需要选择mod_music_entries记录,但首先在mod_music_category.category中分组,然后将每个组作为我需要在mod_music_periods.period中分组的子组。
像:
//只有在mod_music_entries.category_id
中有内容时才写一类mod_music_category.category
//仅当mod_music_entries.period_id
中有内容时才写下此句号 a) mod_music_periods.period
i) mod_music_entries.name
ii) mod_music_entries.name
b)mod_music_periods.period
i) mod_music_entries.name
ii) mod_music_entries.name
//只有在mod_music_entries.category_id
中有内容时才写第二类mod_music_category.category
//仅当mod_music_entries.period_id
中有内容时才写下此句号 a) mod_music_periods.period
i) mod_music_entries.name
ii) mod_music_entries.name
b)mod_music_periods.period
i) mod_music_entries.name
ii) mod_music_entries.name