Table of Contents
Today I will share some useful information. Implementation of curriculum in PHP. , .php course schedule
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

Jul 12, 2016 am 08:58 AM
php today share accomplish Dry information of Class Schedule

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...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles