php 文常练习

来源:互联网 发布:百度软件开发 编辑:程序博客网 时间:2024/06/07 09:56
$a = M('topic')->alias('t')->field('count(e.exercises_type) sum,e.exercises_type type')
                       ->join('pa_exercises  e on e.exercises_id = t.topic_topicid')
                       ->group('e.exercises_type')
                       ->select();
$b = M('topic')->alias('t')->field('count(e.exercises_type) sum,e.exercises_type type')
                       ->where('topic_userid = "'.$re['user_id'].'"')
                       ->join('right join pa_exercises  e on e.exercises_id = t.topic_topicid')
                       ->group('e.exercises_type')
                       ->select();


foreach ($b as $key => $value) {
      foreach ($a as $k => $v) {
           if($v['type'] == $value['type']){
                 $data[$k]['type'] = $v['type'];
                 $data[$k]['sum'] = $value['sum']/$v['sum']*100;
                 $data[$k]['sum'] = $data[$k]['sum'].'%';
             }
      //存值
      if($key == count($b)-1){
             $aa[] = $v['type'];
       }  
    }
 //存值
   $bb[] = $value['type'];
   }
 //取出差集
 $c = array_diff($aa,$bb);
 foreach ($c as $key => $value) {
      $cc['type'] = $value;
      $cc['sum'] = '0%';
      //从数组末尾插入
      array_push($data, $cc);
  }
    //全部进度
    $allcountsum = M('exercises')->count();
    $allcount = M('topic')->where('topic_userid = "'.$re['user_id'].'"')->count();
    $all = $allcount / $allcountsum * 100;
    $data['all'] = $all."%";
原创粉丝点击