vini123

博客园 首页 新随笔 联系 订阅 管理
 1      function saveBookId($array = array())
 2      {
 3         if(empty($array))
 4         {
 5          return;
 6         }
 7         //$bookId = '1079' ; //$array["book_id"];   //老师的book_id;
 8         //$account_id = '1016876';//$array["acount_id"];//老师的account_id; //1016876
 9         //$grade_num = '1'; //$array["grade_num"];  //老师限定学生上课的年级
10         //$class_num = '1';//$array["class_num"];  //老师限定学生上课的班级
11         
12         $bookId = $array["book_id"];   //老师的book_id;
13         $account_id = $array["acount_id"]; //老师的account_id;
14         $grade_num =$array["grade_num"];  //老师限定学生上课的年级
15         $class_num = $array["class_num"];  //老师限定学生上课的班级
16         
17           $sql = "SELECT id FROM teachers WHERE account_id='" .$account_id. "'";
18          $teainfo = $this->Teacher->query($sql);
19          if( !empty($teainfo) )
20          {
21              $teacher_id = $teainfo[0]['teachers']['id'];
22             $sqlTeaBook = "SELECT id,status FROM tea_book WHERE teacher_id='" .$teacher_id. "'";
23             $teaBookinfo = $this->Tea_book->query($sqlTeaBook);
24             if( empty($teaBookinfo) ) 
25             {
26                 $sqlInsTeabook = "INSERT INTO tea_book(`book_id`,`teacher_id`,`grade_id`,`class_id`) VALUES('".$bookId."','".$teacher_id."','".$grade_num."','".$class_num."')";
27                 $this->Tea_book->query($sqlInsTeabook);
28             } 
29             else 
30             {
31                 $sqlInsTeabook = "UPDATE tea_book SET status='1' , book_id='".$bookId."'
32                                   , grade_id='".$grade_num."' , class_id='".$class_num."' WHERE teacher_id='".$teacher_id."'";
33                 
34                 echo $sqlInsTeabook;
35                 $this->Tea_book->query($sqlInsTeabook);
36             }
37          }
38          exit;
39          echo '<pre>';
40          print_r($teainfo);
41          echo '</pre>';
42          exit;
43      }
posted on 2012-09-11 17:17  黑夜丶残枫  阅读(251)  评论(0)    收藏  举报