search
HomeBackend DevelopmentPHP TutorialAbout 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(&#39;Welcome/ajax_page&#39;)?>",
data: "page="+page+"&sou="+sou,
success: function(data){
var str="";
str+="<table border=&#39;1&#39; style=&#39;text-align:center&#39;>";
str+="<tr>";
str+="<td><input type=&#39;checkbox&#39; class=&#39;quan&#39;/></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=&#39;JavaScript:void(0)&#39; class=&#39;lok&#39; fla=&#39;"+item.id+"&#39; id=&#39;lock"+item.id+"&#39;>未锁定</a>"
}else{
var locks = "<a href=&#39;javascript:void(0)&#39; class=&#39;lok&#39; fla=&#39;"+item.id+"&#39; id=&#39;lock"+item.id+"&#39;>锁定</a>"
}
str+="<tr id=&#39;av"+item.id+"&#39;>";
str+="<td><input type=&#39;checkbox&#39; class=&#39;ss&#39; value=&#39;"+item.id+"&#39;/></td>";
str+="<td>"+item.id+"</td>";
str+="<td>"+item.name+"</td>";
str+="<td>"+locks+"</td>";
str+="</tr>";
})
str+="<tr>";
str+="<td><input type=&#39;button&#39; id=&#39;pdel&#39; value=&#39;批量删除&#39;></td>"
str+="</tr>";
str+="</table>";
str+=data.pagestr;
$(&#39;#content&#39;).html(str);
}
})
}
//状态切换
$(document).on(&#39;click&#39;,&#39;.lok&#39;,function(){
var id = $(this).attr(&#39;fla&#39;);
$.ajax({
type: "POST",
url: "<?php echo site_url(&#39;Welcome/upds&#39;)?>",
data: "id="+id,
success: function(msg){
if(msg==1){
$(&#39;#lock&#39;+id).html("锁定");
}else{
$(&#39;#lock&#39;+id).html("未锁定");
}
}
})
})
//批量删除
$(document).on(&#39;click&#39;,&#39;#pdel&#39;,function(){
var ids = $(&#39;.ss&#39;);
var str="";
$.each(ids,function(i,item){
if(ids[i].checked==true){
str=str+&#39;,&#39;+ids[i].value;
}
})
var new_str=str.substr(1);
$.ajax({
type: "POST",
url: "<?php echo site_url(&#39;Welcome/pdels&#39;)?>",
data: "new_str="+new_str,
success: function(msg){
$.each(ids,function(i,item){
if(ids[i].checked==true){
$(&#39;#av&#39;+ids[i].value).remove();
}
})
}
})
})
//全选(复选框)
$(document).on(&#39;click&#39;,&#39;.quan&#39;,function(){
var obj = $(&#39;:checkbox&#39;);
var ids = $(&#39;.ss&#39;);
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[&#39;u_id&#39;]?>"/></td>
//全选(按钮)
$(&#39;.quan&#39;).click(function(){
var ids = $(&#39;input:checkbox&#39;);
$.each(ids,function(i,item){
ids[i].checked=true;
})
})
//全不选
$(&#39;.bu&#39;).click(function(){
var ids = $(&#39;input:checkbox&#39;);
$.each(ids,function(i,item){
ids[i].checked=false;
})
})
//反选
$(&#39;.fan&#39;).click(function(){
var ids = $(&#39;.checks&#39;);
$.each(ids,function(i,item){
ids[i].checked=!ids[i].checked;
})
})
//即点即改
$(document).on(&#39;click&#39;,&#39;.ss&#39;,function(){
var id = $(this).attr(&#39;id&#39;);
var con = $(this).text();
$(this).parent().html("<input type=&#39;text&#39; id=&#39;"+id+"&#39; class=&#39;aa&#39; value=&#39;"+con+"&#39;>");
$(&#39;.aa&#39;).val(&#39;&#39;).focus().val(con);
$(document).on(&#39;blur&#39;,&#39;.aa&#39;,function(){
var id = $(this).attr(&#39;id&#39;);
var cons = $(this).val();
$(this).parent().html("<span id=&#39;"+id+"&#39; class=&#39;ss&#39;>"+cons+"</span>");
$.ajax({
type: "POST",
url: "<?php echo site_url(&#39;Welcome/upd_ji&#39;)?>",
data: "id="+id+"&cons="+cons
})
})
})
//导出
$(document).on(&#39;click&#39;,&#39;#chu&#39;,function(){
var sou = $(&#39;#sou&#39;).val();
location.href="<?php echo site_url(&#39;excel/export&#39;)?>?sou="+sou;
})
//ajax分页(控制层)
public function ajax_page(){
$sou = $this->input->post(&#39;sou&#39;);
$count = $this->db->where("name like &#39;%$sou%&#39;")->count_all_results("peng");
$number = 3;
$this->session->set_userdata(&#39;number&#39;,$number);
$pagecount = ceil($count/$number);
@$page = $_POST[&#39;page&#39;]?$_POST[&#39;page&#39;]:1;
$this->session->set_userdata(&#39;page&#39;,$page);
$start = ($page-1)*$number;
$arr[&#39;list&#39;] = $this->db->where("name like &#39;%$sou%&#39;")->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=&#39;javascript:void(0)&#39; onclick=&#39;ajax_page($up_page)&#39;>上一页</a>";
for($i=1;$i<=$pagecount;$i++){
if($i==$page){
$str .= "--"."<b>$i</b>";
}else{
$str .= "--"."<a href=&#39;javascript:void(0)&#39; onclick=&#39;ajax_page($i)&#39;>$i</a>";
}
}
$str .= "--"."<a href=&#39;javascript:void(0)&#39; onclick=&#39;ajax_page($down_page)&#39;>下一页</a>";
$arr[&#39;pagestr&#39;] = $str;
echo json_encode($arr);
}
//状态切换
public function upds(){
$id = $this->input->post(&#39;id&#39;);
$arr = $this->db->get_where("peng","id=&#39;$id&#39;")->row_array();
if($arr[&#39;state&#39;]==0){
$data[&#39;state&#39;]=1;
$this->db->where("id=&#39;$id&#39;")->update("peng",$data);
echo "1";
}else{
$data[&#39;state&#39;]=0;
$this->db->where("id=&#39;$id&#39;")->update("peng",$data);
echo "2";
}
}
//批量删除
public function pdels(){
$str = $this->input->post(&#39;new_str&#39;);
$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!

Statement
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
What are the advantages of using a database to store sessions?What are the advantages of using a database to store sessions?Apr 24, 2025 am 12:16 AM

The main advantages of using database storage sessions include persistence, scalability, and security. 1. Persistence: Even if the server restarts, the session data can remain unchanged. 2. Scalability: Applicable to distributed systems, ensuring that session data is synchronized between multiple servers. 3. Security: The database provides encrypted storage to protect sensitive information.

How do you implement custom session handling in PHP?How do you implement custom session handling in PHP?Apr 24, 2025 am 12:16 AM

Implementing custom session processing in PHP can be done by implementing the SessionHandlerInterface interface. The specific steps include: 1) Creating a class that implements SessionHandlerInterface, such as CustomSessionHandler; 2) Rewriting methods in the interface (such as open, close, read, write, destroy, gc) to define the life cycle and storage method of session data; 3) Register a custom session processor in a PHP script and start the session. This allows data to be stored in media such as MySQL and Redis to improve performance, security and scalability.

What is a session ID?What is a session ID?Apr 24, 2025 am 12:13 AM

SessionID is a mechanism used in web applications to track user session status. 1. It is a randomly generated string used to maintain user's identity information during multiple interactions between the user and the server. 2. The server generates and sends it to the client through cookies or URL parameters to help identify and associate these requests in multiple requests of the user. 3. Generation usually uses random algorithms to ensure uniqueness and unpredictability. 4. In actual development, in-memory databases such as Redis can be used to store session data to improve performance and security.

How do you handle sessions in a stateless environment (e.g., API)?How do you handle sessions in a stateless environment (e.g., API)?Apr 24, 2025 am 12:12 AM

Managing sessions in stateless environments such as APIs can be achieved by using JWT or cookies. 1. JWT is suitable for statelessness and scalability, but it is large in size when it comes to big data. 2.Cookies are more traditional and easy to implement, but they need to be configured with caution to ensure security.

How can you protect against Cross-Site Scripting (XSS) attacks related to sessions?How can you protect against Cross-Site Scripting (XSS) attacks related to sessions?Apr 23, 2025 am 12:16 AM

To protect the application from session-related XSS attacks, the following measures are required: 1. Set the HttpOnly and Secure flags to protect the session cookies. 2. Export codes for all user inputs. 3. Implement content security policy (CSP) to limit script sources. Through these policies, session-related XSS attacks can be effectively protected and user data can be ensured.

How can you optimize PHP session performance?How can you optimize PHP session performance?Apr 23, 2025 am 12:13 AM

Methods to optimize PHP session performance include: 1. Delay session start, 2. Use database to store sessions, 3. Compress session data, 4. Manage session life cycle, and 5. Implement session sharing. These strategies can significantly improve the efficiency of applications in high concurrency environments.

What is the session.gc_maxlifetime configuration setting?What is the session.gc_maxlifetime configuration setting?Apr 23, 2025 am 12:10 AM

Thesession.gc_maxlifetimesettinginPHPdeterminesthelifespanofsessiondata,setinseconds.1)It'sconfiguredinphp.iniorviaini_set().2)Abalanceisneededtoavoidperformanceissuesandunexpectedlogouts.3)PHP'sgarbagecollectionisprobabilistic,influencedbygc_probabi

How do you configure the session name in PHP?How do you configure the session name in PHP?Apr 23, 2025 am 12:08 AM

In PHP, you can use the session_name() function to configure the session name. The specific steps are as follows: 1. Use the session_name() function to set the session name, such as session_name("my_session"). 2. After setting the session name, call session_start() to start the session. Configuring session names can avoid session data conflicts between multiple applications and enhance security, but pay attention to the uniqueness, security, length and setting timing of session names.

See all articles

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 Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.