我有一张由主流和主题组成的表格。在租约中,每个主流有五个主题。
我想打印主题和主流,但我不需要重复主流。
我们可以通过mysql查询来处理吗?如果是的话,该怎么办?
这是表
的表结构CREATE TABLE IF NOT EXISTS `wp_c_subject` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`mai_stream` varchar(40) DEFAULT NULL,
`subject` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=122 ;
foreach($stream as $value_str){
echo $value_str->mai_stream;
echo '<br>';
foreach($employee_subjects as $key=> $value){
if ($value_str->mai_stream==$value->mai_stream)
echo 'I am in '.$value->mai_stream;
echo '<table><tbody>';
echo '<tr><td style="width:300px;">'.$value->subject.'</td>'.'<td style="width:200px;padding:5px;">'.$value->skill_level;'</td></tr>';
echo '</table></tbody>';
// echo '</br>';echo '</br>';
}
}
以下代码始终打印main_stream。
//printing subject information and subject main stream
$employee_subjects=$wpdb->get_results("SELECT wp_c_subject.subject, wp_c_subject.mai_stream ,wp_c_skilllist.skill_level FROM `wp_c_users`
JOIN wp_c_skilllist ON wp_c_skilllist.user_id = wp_c_users.id
JOIN wp_c_subject ON wp_c_subject.id = wp_c_skilllist.subject_id
WHERE wp_c_users.first_name = 'abc'
ORDER BY wp_c_subject.mai_stream DESC");
//retriving main strams for subjects
$stream=$wpdb->get_results("SELECT wp_c_subject.mai_stream FROM `wp_c_users`
JOIN wp_c_skilllist ON wp_c_skilllist.user_id = wp_c_users.id
JOIN wp_c_subject ON wp_c_subject.id = wp_c_skilllist.subject_id
WHERE wp_c_users.first_name = 'abc'
ORDER BY wp_c_subject.mai_stream DESC");