


About the CI framework to implement ajax paging and select all, invert selection, unselect and batch deletion code
CodeIgniter is a small but powerful PHP framework. This article mainly introduces the complete code of the CI framework (ajax paging, select all, inverse selection, no selection, batch deletion). Friends who need it can refer to it
CodeIgniter is a small but powerful PHP framework. A simple and "elegant" toolkit for developers to build fully functional web applications. It is a relatively mainstream PHP framework.
Let me introduce to you the complete code of the CI framework (ajax paging, select all, inverse selection, no selection, batch deletion). The specific code is as follows:
//ajax分页+搜索(视图层) function ajax_page(page){ var sou = $('#sou').val(); $.ajax({ type: "POST", dataType: "json", url: "<?PHP echo site_url('Welcome/ajax_page')?>", data: "page="+page+"&sou="+sou, success: function(data){ var str=""; str+="<table border='1' style='text-align:center'>"; str+="<tr>"; str+="<td><input type='checkbox' class='quan'/></td>"; str+="<td>ID</td>"; str+="<td>用户名</td>"; str+="<td>操作</td>"; str+="</tr>"; $.each(data.list,function(i,item){ if(item.state==0){ var locks = "<a href='JavaScript:void(0)' class='lok' fla='"+item.id+"' id='lock"+item.id+"'>未锁定</a>" }else{ var locks = "<a href='javascript:void(0)' class='lok' fla='"+item.id+"' id='lock"+item.id+"'>锁定</a>" } str+="<tr id='av"+item.id+"'>"; str+="<td><input type='checkbox' class='ss' value='"+item.id+"'/></td>"; str+="<td>"+item.id+"</td>"; str+="<td>"+item.name+"</td>"; str+="<td>"+locks+"</td>"; str+="</tr>"; }) str+="<tr>"; str+="<td><input type='button' id='pdel' value='批量删除'></td>" str+="</tr>"; str+="</table>"; str+=data.pagestr; $('#content').html(str); } }) } //状态切换 $(document).on('click','.lok',function(){ var id = $(this).attr('fla'); $.ajax({ type: "POST", url: "<?php echo site_url('Welcome/upds')?>", data: "id="+id, success: function(msg){ if(msg==1){ $('#lock'+id).html("锁定"); }else{ $('#lock'+id).html("未锁定"); } } }) }) //批量删除 $(document).on('click','#pdel',function(){ var ids = $('.ss'); var str=""; $.each(ids,function(i,item){ if(ids[i].checked==true){ str=str+','+ids[i].value; } }) var new_str=str.substr(1); $.ajax({ type: "POST", url: "<?php echo site_url('Welcome/pdels')?>", data: "new_str="+new_str, success: function(msg){ $.each(ids,function(i,item){ if(ids[i].checked==true){ $('#av'+ids[i].value).remove(); } }) } }) }) //全选(复选框) $(document).on('click','.quan',function(){ var obj = $(':checkbox'); var ids = $('.ss'); if(obj[0].checked==true){ $.each(ids,function(i,item){ ids[i].checked=true; }) }else{ $.each(ids,function(i,item){ ids[i].checked=false; }) } }) <td><input type="checkbox" class="checks" value="<?php echo $val['u_id']?>"/></td> //全选(按钮) $('.quan').click(function(){ var ids = $('input:checkbox'); $.each(ids,function(i,item){ ids[i].checked=true; }) }) //全不选 $('.bu').click(function(){ var ids = $('input:checkbox'); $.each(ids,function(i,item){ ids[i].checked=false; }) }) //反选 $('.fan').click(function(){ var ids = $('.checks'); $.each(ids,function(i,item){ ids[i].checked=!ids[i].checked; }) }) //即点即改 $(document).on('click','.ss',function(){ var id = $(this).attr('id'); var con = $(this).text(); $(this).parent().html("<input type='text' id='"+id+"' class='aa' value='"+con+"'>"); $('.aa').val('').focus().val(con); $(document).on('blur','.aa',function(){ var id = $(this).attr('id'); var cons = $(this).val(); $(this).parent().html("<span id='"+id+"' class='ss'>"+cons+"</span>"); $.ajax({ type: "POST", url: "<?php echo site_url('Welcome/upd_ji')?>", data: "id="+id+"&cons="+cons }) }) }) //导出 $(document).on('click','#chu',function(){ var sou = $('#sou').val(); location.href="<?php echo site_url('excel/export')?>?sou="+sou; }) //ajax分页(控制层) public function ajax_page(){ $sou = $this->input->post('sou'); $count = $this->db->where("name like '%$sou%'")->count_all_results("peng"); $number = 3; $this->session->set_userdata('number',$number); $pagecount = ceil($count/$number); @$page = $_POST['page']?$_POST['page']:1; $this->session->set_userdata('page',$page); $start = ($page-1)*$number; $arr['list'] = $this->db->where("name like '%$sou%'")->limit($number,$start)->get("peng")->result_array(); $up_page = $page-1<1?1:$page-1; $down_page = $page+1>$pagecount?$pagecount:$page+1; $str = ""; $str .= "<a href='javascript:void(0)' onclick='ajax_page($up_page)'>上一页</a>"; for($i=1;$i<=$pagecount;$i++){ if($i==$page){ $str .= "--"."<b>$i</b>"; }else{ $str .= "--"."<a href='javascript:void(0)' onclick='ajax_page($i)'>$i</a>"; } } $str .= "--"."<a href='javascript:void(0)' onclick='ajax_page($down_page)'>下一页</a>"; $arr['pagestr'] = $str; echo json_encode($arr); } //状态切换 public function upds(){ $id = $this->input->post('id'); $arr = $this->db->get_where("peng","id='$id'")->row_array(); if($arr['state']==0){ $data['state']=1; $this->db->where("id='$id'")->update("peng",$data); echo "1"; }else{ $data['state']=0; $this->db->where("id='$id'")->update("peng",$data); echo "2"; } } //批量删除 public function pdels(){ $str = $this->input->post('new_str'); $this->db->where("id in($str)")->delete("peng"); }
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to use CI framework to achieve front-end and back-end separation of the framework
About CI framework infinite classification and recursion Implementation
How to use the CodeIgniter framework to implement image uploading methods
The above is the detailed content of About the CI framework to implement ajax paging and select all, invert selection, unselect and batch deletion code. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

RESTAPI design principles include resource definition, URI design, HTTP method usage, status code usage, version control, and HATEOAS. 1. Resources should be represented by nouns and maintained at a hierarchy. 2. HTTP methods should conform to their semantics, such as GET is used to obtain resources. 3. The status code should be used correctly, such as 404 means that the resource does not exist. 4. Version control can be implemented through URI or header. 5. HATEOAS boots client operations through links in response.

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

The main function of anonymous classes in PHP is to create one-time objects. 1. Anonymous classes allow classes without names to be directly defined in the code, which is suitable for temporary requirements. 2. They can inherit classes or implement interfaces to increase flexibility. 3. Pay attention to performance and code readability when using it, and avoid repeatedly defining the same anonymous classes.
