Home > Backend Development > PHP Tutorial > Let me share some useful information today. Implementation of curriculum in PHP. ,.php curriculum_PHP tutorial

Let me share some useful information today. Implementation of curriculum in PHP. ,.php curriculum_PHP tutorial

WBOY
Release: 2016-07-12 08:58:40
Original
3158 people have browsed it

Today I will share some useful information. Implementation of curriculum in PHP. , .php course schedule

First post the code, and then go into details after posting the code:

Front HTML:

<span> 1</span>  <span><</span><span>div </span><span>id</span><span>="studentRead"</span><span> class</span><span>="reading"</span><span> style</span><span>="z-index:10"</span> <span>></span>
<span> 2</span>                          <span><</span><span>div </span><span>class</span><span>="class-table"</span><span>></span>
<span> 3</span>                             <span><</span><span>div </span><span>class</span><span>="class-table-tit clearfix"</span><span>></span>
<span> 4</span>                                 <span><</span><span>h3 </span><span>class</span><span>="fl"</span><span>></span>班级课程表<span></</span><span>h3</span><span>></span>
<span> 5</span>                                 <span><</span><span>a </span><span>class</span><span>="fr"</span><span> id </span><span>='studentEditKcb' </span><span>attr</span><span>="edit"</span><span> onclick </span><span>= "editKcb(this);"</span><span> style</span><span>="cursor:pointer;"</span><span>></span><span>编辑
</span><span> 6</span>                                 <span></</span><span>a</span><span>></span>
<span> 7</span>                             <span></</span><span>div</span><span>></span>
<span> 8</span>                                 <span><</span><span>table </span><span>border</span><span>="0"</span><span> cellspacing</span><span>="0"</span><span> cellpadding</span><span>="0"</span><span> id </span><span>= "myTable"</span><span>></span>
<span> 9</span>                                     <span><</span><span>tr</span><span>></span>
<span>10</span>                                         <span><</span><span>th </span><span>width</span><span>="5%"</span><span>></</span><span>th</span><span>></span>
<span>11</span>                                         <span><</span><span>th </span><span>width</span><span>="19%"</span><span>></span>周一<span></</span><span>th</span><span>></span>
<span>12</span>                                         <span><</span><span>th </span><span>width</span><span>="19%"</span><span>></span>周二<span></</span><span>th</span><span>></span>
<span>13</span>                                         <span><</span><span>th </span><span>width</span><span>="19%"</span><span>></span>周三<span></</span><span>th</span><span>></span>
<span>14</span>                                         <span><</span><span>th </span><span>width</span><span>="19%"</span><span>></span>周四<span></</span><span>th</span><span>></span>
<span>15</span>                                         <span><</span><span>th </span><span>width</span><span>="19%"</span><span>></span>周五<span></</span><span>th</span><span>></span>
<span>16</span>                                     <span></</span><span>tr</span><span>></span>
<span>17</span>                                     <span><</span><span>tr </span><span>id </span><span>= "focustr"</span><span>></span>
<span>18</span>                                         <span><</span><span>td </span><span>rowspan</span><span>="4"</span><span> class</span><span>="td-bg"</span><span>></span>上<span><</span><span>br</span><span>/></span>午<span></</span><span>td</span><span>></span>
<span>19</span>                                         <span><</span><span>volist </span><span>name </span><span>= "dataListStu"</span><span> id </span><span>= "val"</span><span> offset</span><span>="0"</span><span> length</span><span>='1'</span><span>></span>
<span>20</span>                                             <span><</span><span>volist </span><span>name </span><span>= "val"</span><span> id </span><span>= "value"</span><span>></span>
<span>21</span>                                             <span><</span><span>td</span><span>></span>
<span>22</span>                                                 <span><</span><span>input  </span><span>id </span><span>= "focusId"</span><span> readonly</span><span>="true"</span><span> maxlength</span><span>='7' </span><span>type</span><span>="text"</span><span>  value</span><span>="{$value}"</span> <span>/></span>
<span>23</span>                                             <span></</span><span>td</span><span>></span>
<span>24</span>                                             <span></</span><span>volist</span><span>></span>
<span>25</span>                                         <span></</span><span>volist</span><span>></span>
<span>26</span>                                     <span></</span><span>tr</span><span>></span>
<span>27</span>                                     <span><</span><span>volist </span><span>name </span><span>= "dataListStu"</span><span> id </span><span>= "val"</span><span> offset</span><span>="1"</span><span> length</span><span>='3'</span><span>></span>
<span>28</span>                                         <span><</span><span>tr</span><span>></span>
<span>29</span>                                             <span><</span><span>volist </span><span>name </span><span>= "val"</span><span> id </span><span>= "value"</span><span>></span>
<span>30</span>                                             <span><</span><span>td</span><span>></span>
<span>31</span>                                                 <span><</span><span>input   </span><span>readonly</span><span>="true"</span><span> maxlength</span><span>='7' </span><span>type</span><span>="text"</span><span>  value</span><span>="{$value}"</span> <span>/></span>
<span>32</span>                                             <span></</span><span>td</span><span>></span>
<span>33</span>                                             <span></</span><span>volist</span><span>></span>
<span>34</span>                                         <span></</span><span>tr</span><span>></span>
<span>35</span>                                     <span></</span><span>volist</span><span>></span>
<span>36</span>                                     <span><</span><span>tr</span><span>></span>
<span>37</span>                                         <span><</span><span>td </span><span>rowspan</span><span>="4"</span><span> class</span><span>="td-bg"</span><span>></span>下<span><</span><span>br</span><span>/></span>午<span></</span><span>td</span><span>></span>
<span>38</span>                                         <span><</span><span>volist </span><span>name </span><span>= "dataListStu"</span><span> id </span><span>= "val"</span><span> offset</span><span>="4"</span><span> length</span><span>='1'</span><span>></span>
<span>39</span>                                             <span><</span><span>volist </span><span>name </span><span>= "val"</span><span> id </span><span>= "value"</span><span>></span>
<span>40</span>                                             <span><</span><span>td</span><span>></span>
<span>41</span>                                                 <span><</span><span>input   </span><span>readonly</span><span>="true"</span><span> maxlength</span><span>='7' </span><span>type</span><span>="text"</span><span>  value</span><span>="{$value}"</span> <span>/></span>
<span>42</span>                                             <span></</span><span>td</span><span>></span>
<span>43</span>                                             <span></</span><span>volist</span><span>></span>
<span>44</span>                                         <span></</span><span>volist</span><span>></span>
<span>45</span>                                     <span></</span><span>tr</span><span>></span>
<span>46</span>                                     <span><</span><span>volist </span><span>name </span><span>= "dataListStu"</span><span> id </span><span>= "val"</span><span> offset</span><span>="5"</span><span> length</span><span>='3'</span><span>></span>
<span>47</span>                                         <span><</span><span>tr</span><span>></span>
<span>48</span>                                             <span><</span><span>volist </span><span>name </span><span>= "val"</span><span> id </span><span>= "value"</span><span>></span>
<span>49</span>                                             <span><</span><span>td</span><span>></span>
<span>50</span>                                                 <span><</span><span>input   </span><span>readonly</span><span>="true"</span><span> maxlength</span><span>='7' </span><span>type</span><span>="text"</span><span>  value</span><span>="{$value}"</span> <span>/></span>
<span>51</span>                                             <span></</span><span>td</span><span>></span>
<span>52</span>                                             <span></</span><span>volist</span><span>></span>
<span>53</span>                                         <span></</span><span>tr</span><span>></span>
<span>54</span>                                     <span></</span><span>volist</span><span>></span>
<span>55</span>                             <span></</span><span>table</span><span>></span>
<span>56</span>                         <span></</span><span>div</span><span>></span>            
<span>57</span>                  <span></</span><span>div</span><span>></span>
Copy after login

CSS:

Let me share some useful information today. Implementation of curriculum in PHP. ,.php curriculum_PHP tutorial 1 /*Course Schedule*/ 2 .class-table{ 3 background: #f6fafe; 4 border: 1px solid #e9ecee; 5 -webkit-border-radius: 5px; 6 width: 478px; 7 padding: 10px 20px 20px; 8 -moz-border-radius: 5px; 9 border-radius: 5px; 10 } 11 .class-table-tit{ 12 height: 30px; 13 line-height: 30px; 14 } 15 .class-table-tit h3{ 16 color: #666; 17 font-size: 16px; 18 font-weight: bold; 19 } 20 .class-table-tit a{ 21 font-size: 14px; 22 color: #187aff; 23 } 24 .class-table table{ 25 width: 100%; 26 } 27 .class-table table th{ 28 height: 40px; 29 background: #aedf74; 30 text-align: center; 31 border-right: 1px solid #9dc968; 32 } 33 .class-table table th:first-child{ 34 background: #89cc4a; 35 border-right: 0; 36 } 37 .class-table table td{ 38 height: 30px; 39 border: solid #e3eaf1; 40 border-width: 0 1px 1px 0; 41 text-align: center; 42 font-size: 14px; 43 color: #666; 44 } 45 .class-table table td input{ 46 border: 0; 47 height: 20px; 48 line-height: 20px; 49 width: 70%; 50 background: none; 51 text-align: center; 52 color: #666; 53 } 54 .class-table table td input.activeStu{ 55 background: #66a7ff; 56 color: #fff; 57 } 58 .td-bg{ 59 background: #c4ea96; 60 } View Code

JS part:

Let me share some useful information today. Implementation of curriculum in PHP. ,.php curriculum_PHP tutorial 1 var flagkcb = true; 2 //Control curriculum editing and completion. 3 function editKcb(obj){ 4 var editHtml = $(obj).attr('attr'); 5 if(editHtml == 'edit'){ 6 $(".class-table table td input").attr('class','activeStu'); 7 $(".class-table input").attr('readonly',false); 8 $("#studentEditKcb").html('完成'); 9 $(".class-table table td input").attr('class','activeStu'); 10 $("#focustr td:nth-child(2) input").focus(); 11 $(obj).attr('attr','save'); 12 }else{ 13 if(flagkcb){ 14 reloadKCB(); 15 $(obj).attr('attr','edit'); 16 }else{ 17 alert('数据保存中,请勿重复提交!'); 18 } 19 } 20 } 21 22 23 24 25 //获取页面表格内的数据 26 function getTableValue(){ 27 var kecbInput = $(".activeStu"); 28 var i = 0; 29 var j= 0; 30 var data = []; 31 var data2 = []; 32 $.each(kecbInput,function(k,v){ 33 data2[j] = v.value; 34 j ; 35 if((k 1)%5==0){ 36 j = 0; 37 data[i] = data2; 38 data2 = []; 39 i ; 40 } 41 }); 42 return data; 43 } 44 45 //课程表 46 function reloadKCB(){ 47 $("#records").hide(); 48 $("#classba").hide(); 49 $("#classhare").hide(); 50 $("#homework").hide(); 51 $('#studentRead').show(); 52 var data = getTableValue(); 53 //根据ajax加载,若加载后数据为空,则证明该学生没有编辑过课程表,直接显示 54 $.ajax({ 55 type:"POST", 56 url: U('public/Index/savekcb'), 57 data:{"data":data}, 58 dataType:"json", 59 success:function(response){ 60 flagkcb = true; 61 $(".class-table table td input").removeAttr('class','activeStu'); 62 $(".class-table input").attr('readonly',true); 63 $("#studentEditKcb").html('编辑'); 64 }, 65 error:function(msg){ 66 flagkcb = true; 67 alert('保存失败请重试'); 68 // $("#studentRead").show(); 69 // $("#studentRead").html("").html("

加载失败,请重试!

");
70 } 71 }); 72 73 // 74 // } 75 } View Code

Backend part:

Let me share some useful information today. Implementation of curriculum in PHP. ,.php curriculum_PHP tutorial 1 /** 2 * Personal editing and saving of student curriculum 3 */ 4 public function savekcb(){ 5 $saveResult = array('status'=>200,'msg'=>'Save successfully'); 6 //What you get is a two-dimensional array 7 $data = $_REQUEST['data']; 8 $user=$GLOBALS['ts']['cyuserdata']; 9 //Convert the curriculum data into json format and save it 10 $saveArray = json_encode($data); 11 //space user id 12 $uid = $this->uid; 13 //user cyuid 14 $saveData = array(); 15 $saveData['cyuid'] = $user['user']['cyuid']; 16 $saveData['uid'] = $uid; 17 $saveData['kcb'] = $saveArray; 18 //Creation time 19 $saveData['createtime'] = date('Y-m-d H:i:s'); 20 $saveData['updatetime'] = date('Y-m-d H:i:s'); 21 22 $isExit = D('StudentKcb')->where("`uid`=$uid")->find( ); 23 if($isExit){ 24 unset($saveData['createtime']); 25 $result = D('StudentKcb')->where("`uid`=$uid")->save( $saveData); 26 }else{ 27 $result = D('StudentKcb')->add($saveData); 28 } 29 if(!$result){ 30 $saveResult = array('status'=>400,'msg'=>'Save failed'); 31 }else{ 32 $stuKcb = json_decode($result['kcb'],true); 33 S($this->uid."_student_kcb",$stuKcb,60*5); 34 } 35 exit(json_encode($saveResult)); 36 }37 38 /** 39 * Personal student space page course schedule initialization 40 */ 41 private function initkcb(){ 42 $result = S($this->uid."_student_kcb"); 43 if(!$result){ 44 //space user id 45 $uid = $this->uid; 46 $result = D('StudentKcb')->where("`uid`=$uid")->find(); 47 $result = json_decode($result['kcb'],true); 48 if(!$result){ 49 $result = array( 50 0=>array('','','','',''), 51 1=>array('','','','',''), 52 2=>array('','','','',''), 53 3=>array('','','','',''), 54 4=>array('','','','',''), 55 5=>array('','','','',''), 56 6=>array('','','','',''), 57 7=>array('','','','',''), 58 ); 59 } 60 S($this->uid."_student_kcb",$result,60*5); 61 } 62 63 $this->assign('dataListStu',$result); 64 } 65 66 } View Code

Let’s start with the details: Let’s take a rendering first. Before editing:

Editing (click the upper right corner to edit):

Added some positioning and background color changes. Let users have a better experience,

Step one: When receiving this request, first I was thinking about how to get the data in the table. The first thing I thought of was to use nested for loops, and then Add judgment and add data to the defined array, but later I thought that would lead to

The data is correct, but there is a problem with the stored data. Let me give you an example: data[]={

data[1]={

data[1][1] = 0;

... ...

  }

Data[2]={data[2][0]= 1;

... ...

  }

   … ...

 }

It means that when I loop by row, because the first and fifth rows have an extra , my subscript will start from 1 instead of starting from 0 like other rows.

Later I decided not to do this. I added a unique class and got the sentence var kecbInput = $(".activeStu");. This sentence means to get the collection of all objects with class="activeStu".

As for the rest of the loop writing method, if you don’t understand it, you can ask directly in the article, I won’t go into details.

The second step : After writing and obtaining the value, all that is left is to pass the value to the background. The idea is that each student has a unique course of his own surface. It's still the old method of using ajax to pass values. When saving data, save the data in json format for storage.

The third step : Pass the value to the front page and display it. In fact, many students here say that this is simple. Isn’t it just a for loop using js to control the display? Well, then it proves that you have not grasped the usefulness of the php volist tag!

Using volist, you can easily display the value you want to assign just like the code I posted.

A lot of things are actually in the posted code. My expression ability is not very good, or I don’t understand these things to a certain extent.

Originally I wanted to share some ideas with everyone, but after writing and discovering, there is actually nothing to say. That’s it. But I still think it’s better to post it. Maybe some people need it? Even though it was simple, it didn’t take long. But I believe that if you keep sharing, you may have a deeper understanding.

    

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1102847.htmlTechArticleToday I will share some useful information. Implementation of curriculum in PHP. , .php course schedule first paste the code, and then elaborate after the code is posted: HTML in the previous paragraph: 1 div id ="studentRead" class ="reading" style ="z-i...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template