使用JS批量选 * 能实现更改数据库中的status状态值(批量展示)
作者:yangzailu1990 发布时间:2024-01-28 00:18:38
标签:js,数据库,status
我们在开发项目的时候经常会在后台管理时用到批量展示功能来动态的修改数据库的值。下面以修改数据库的status状态值来实现批量展示功能。批量选 * 能引用js来实现。
前端html代码:
<table class="mlt" style="border:1px solid red;">
<thead>
<tr>
<if condition="$type eq 'pg'">
<th colspan="9" style="text-align:left;padding-left:20px;background-color:#e5e4e4;color:#c10e23;">实物商品</th>
<else/>
<th colspan="8" style="text-align:left;padding-left:20px;background-color:#e5e4e4;color:#c10e23;">虚拟商品</th>
</if>
<th style="background-color:#e5e4e4;">
<a href="{:U('Mall/AddMall',array('type'=>$type))}" style="color:#c10e23;text-decoration:none;">+新增商品</a></th>
</tr>
<tr>
<th style="background-color:#f7f7f7;width:8%;text-align:center;" class="lf">
<input name='chkAll' type='checkbox' id='chkAll' onClick="checkAll(this, 'id[]')" value='checkbox' /> 全选
</th>
<th style="background-color:#f7f7f7;width:8%;" class="lf">商品编号</th>
<th style="background-color:#f7f7f7;width:13%;" class="lf">名称</th>
<th style="background-color:#f7f7f7;width:18%;" class="lf">标题</th>
<if condition="$type eq 'pg'">
<th style="background-color:#f7f7f7;width:8%;" class="lf">品牌</th>
</if>
<th style="background-color:#f7f7f7;width:8%;" class="lf">组别</th>
<th style="background-color:#f7f7f7;width:5%;" class="lf">排序</th>
<th style="background-color:#f7f7f7;width:5%;" class="lf">状态</th>
<th style="background-color:#f7f7f7;width:10%;">图标</th>
<th style="background-color:#f7f7f7;text-align:center;" class="lf">操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td class="lf" style="text-align:center;">
<input name='id[]' type='checkbox' value='{$vo.id}' onClick="checkItem(this, 'chkAll')">
</td>
<td class="lf">{$vo['code']}</td>
<td class="lf">{$vo['name']}</td>
<td class="lf">{$vo['title']}</td>
<if condition="$type eq 'pg'">
<td class="lf">{$vo['brand']}</td>
</if>
<td class="lf">{$vo['ggroup']}</td>
<td class="lf">{$vo['sortno']}</td>
<td class="lf"><if condition="$vo['status'] eq 1">展示<else/>不展示</if></td>
<td><img src="{$vo['base_img']}" style="width:40px;" /></td>
<td class="lf" style="text-align:center;">
<a href="{:U('Mall/NextLevel',array('pid'=>$vo['id']))}" class='cz' style="text-decoration:none;">编辑子信息</a>
<a href="{:U('Mall/UpdateMall',array('id'=>$vo['id']))}" class='cz' style="text-decoration:none;margin:0 7px;">编辑</a>
<a href="{$Think.config.WEB_URL}/Shop/GoodsDetails.html?pid={$vo['id']}&type={$vo['type']}" class='cz' style="text-decoration:none;" target="_Blank">查看</a>
</td>
</tr>
</volist>
<tr height="45">
<td colspan="10" style="text-align:left;padding-left:40px;">
<input type="button" id="btn_show" value="批量展示" class="btn_normal" style="width:100px;margin-left:20px;">
</td>
</tr>
</tbody>
</table>
<div>{$page}</div>
js代码使用ajax提交代码到后台GoodsShow()方法:
<script type="text/javascript">
var ids = []; //把得到的is转化为数组形式
$('#btn_show').click(function(){
btnCheck('展示');
data = {
"ids":ids
};
$.ajax({
type:"POST",
url:"{:U('Mall/GoodsShow')}",
data:data,
//dataType:"json",
success:function(msg){
if(msg == 00){ //如果msg=00则修改成功
alert("批量展示成功");
window.location.href='/index.php/Admin/Mall/MallList'; //修改完成后自动刷新
}else{
alert("批量展示失败,请重新编辑");
}
},
error:function(){
alert("批量编辑失败,请重新编辑"); //错误提示
}
});
});function btnCheck(info){
var obj = $("input[name='id[]']:checked").each(function(){ //得到选中的id的每一个值并且这个值为一个数组
ids.push($(this).val());
});
if (ids == false) {
alert("请选定要"+info+"的商品");
return false;
}else {
return ids;
}
}
</script>
后台GoodsShow()方法:
public function GoodsShow(){
$goods=M('shop_goods_info'); //实例化要使用的数据表
$data = I(); //获取前台页面获取的id值(这个值为一个一位数组)
//var_dump(I('ids'));die(); //打印
$id=implode(',',I('ids')); //把得到的这个数组用implode方法拆分
//var_dump(I('id'));die(); //打印查看
$order=$goods->where("id in ($id)")->setField('status','1'); //用得到的$id的值匹配数据库中的id值,并设置id下的status字段值为1.
if($order>=1){ // 如果...else...
$remark="00";
}else{
$remark="01";
}
echo $remark;
}
以上所述是小编给大家介绍的使用JS批量选 * 能实现更改数据库中的status状态值(批量展示)网站的支持!
来源:http://www.cnblogs.com/yangzailu/archive/2016/11/22/6088622.html
0
投稿
猜你喜欢
- 今天群里有人问了个问题是这样的: 然后有群友是这样回答的 select name,sum(case when stype=4 t
- 事务隔离级别设置set global transaction isolation level read committed; //全局的se
- 我们知道map() 会根据提供的函数对指定序列做映射。 第一个参数 function 以参数序列中的每一个元素调用 function函数,返
- 目录1 matplot入门指南2 安装与导入3 图的构成3 总结1 matplot入门指南matplotlib是Python科学计算中使用最
- Mysql查看表、字段信息查看表信息使用MySQL创建的表,无论是表注释、索引,还是字段的类型等等,都会存到MySQL自带的库表中,可以通过
- 1. 首先是环境的安装 (本人使用的是PyCharm,python3.6)pip3 install PyQt5 (没有指定版本的话,默认会安
- 本文实例讲述了Python 闭包,函数分隔作用域,nonlocal声明非局部变量操作。分享给大家供大家参考,具体如下:实例对象也可以实现闭包
- sql server 2008 r2 express是什么版本express是精简版的意思 r2是2008的第2版本,推荐使用。SQL Se
- 进入PyCharm后,点击File→Open,然后在弹窗中选择需要导入项目的文件夹;打开了python项目后,需要配置该项目对应的pytho
- 本文实例讲述了python实现从字典中删除元素的方法。分享给大家供大家参考。具体分析如下:python的字典可以通过del方法进行元素删除,
- System.Data.OleDb.OleDbDataAdapter与System.Data.OleDb.OleDbDataReader的区
- 当我们的程序报错时,解释器会将整个异常的堆栈信息全部输出出来,举个例子:def foo(): &
- 当需要从 JavaScript 中的数组中获取最后一个元素时,有多种选择,本文将提供 3 种可用方法。1. 数组 length 属性??le
- 本文实例为大家分享了python比特币初始配置的具体代码,供大家参考,具体内容如下# -*- coding: utf-8 -*- "
- 一个post类型的接口怎么编写脚本实现1、打开网页,在fiddler上获取到接口的URL2、用Python的requests库实现impor
- 我开发了一个程序,数据在服务器端处理,通过ODBC和Access通讯。在实际应用中,调用后台存储过程不方便,花费时间也长。有什么好办法可以在
- 项目场景:常见的表单填写中都会遇到,比如新增信息,修改信息等,如下图相信大家对上面的验证都非常熟悉了,不多哔哔 本篇文章主要 想写 验证规则
- 一、前言 axios的封装和api接口的统一管理,其实主要目的就是在帮助我们简化代码和利于后期的更新维护。二、axios封装步骤安
- 就目前互联网上大小网站而言,大部分都是采用ASP+ACCESS/SQL Server或者PHP+MySQL来编写;事实上,ASP和MySQL
- 前言在访问量大的时候,为了提高查询效率,我们会将数据先缓存到redis中。先查询redis,查询不到再去查询数据库,实现这个逻辑也不复杂,写