0

我有一张由主流和主题组成的表格。在lealet,每个主流都有五个主题。

我想打印 subject 和 Main stream ,但我不需要重复 main stream 。

我们可以通过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");
4

0 回答 0