您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程
ecshop后台分页功能应用实例
亦玉2024-11-28 23:29:04ecshop商城教程已有人查阅
导读Ecshop分页规则,分以下几个步骤 1.点击类别,获取第一页获取默认分类列表数据 2.点击“下一页”,采用ajax调取分页内容 实例分析(比如订单列表分页admin/order.php)
Ecshop分页规则,分以下几个步骤
1.点击类别,获取第一页获取默认分类列表数据
2.点击“下一页”,采用ajax调取分页内容
实例分析(比如订单列表分页admin/order.php)
1.先写一个function order_list() 模块,里面要包括可以进行排序,分页,查询等功能
2.在order.php里面写一个elseif ($_REQUEST['act'] == 'list') ,这里是显示默认分页数据
3.在order.php写一个query(listtable.js默认的是先读取$_REQUEST['act'] == 'query')排序、分页、查询都在query里面完成
4.html页面(默认order_list.html完整代码)
实战 ”微仓功能“
1.我先写一个function depot_log_list,可以进行排序、分类、查询。这个function里面很有讲究的
重点代码
实例代码
实例代码
分页实例化结构代码
1.点击类别,获取第一页获取默认分类列表数据
2.点击“下一页”,采用ajax调取分页内容
实例分析(比如订单列表分页admin/order.php)
1.先写一个function order_list() 模块,里面要包括可以进行排序,分页,查询等功能
2.在order.php里面写一个elseif ($_REQUEST['act'] == 'list') ,这里是显示默认分页数据
3.在order.php写一个query(listtable.js默认的是先读取$_REQUEST['act'] == 'query')排序、分页、查询都在query里面完成
4.html页面(默认order_list.html完整代码)
实战 ”微仓功能“
1.我先写一个function depot_log_list,可以进行排序、分类、查询。这个function里面很有讲究的
重点代码
function depot_list()
{
//*f.获取上一次保存的查询条件(如果上一次有进行查询过,则直接从f开始)
$result = get_filter();
if ($result === false) {
// a.查询条件
$filter['goods_id'] = empty($_REQUEST['goods_id']) ? '' : trim($_REQUEST['goods_id']);
//b.记录总条数
$filter['record_count'] = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('depot_log') . $ex_where);
//c.分页大小
$filter = page_and_size($filter); //d.查询的sql
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('depot_log') . $ex_where .
" order by createtime desc LIMIT " . $filter['start'] . ',' . $filter['page_size'];
//e.保存查询条件(cookie保存)
set_filter($filter, $sql);
}
else
{
//*f.获取上一次保存的查询条件(如果没有进行查询过,则从a查询。)
$sql = $result['sql'];
$filter = $result['filter']; }
$depot_list = $GLOBALS['db']->getAll($sql);
//g.组合成系统默认查询条件
$arr = array('depot_list' => $depot_list, 'filter' => $filter,
'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
return $arr;
}
e.f这两步骤非常的重要,还有if($result===false){}也非常重要实例代码
function depot_list()
{
$result = get_filter();
if ($result === false)
{
$filter['user_id'] = empty($_REQUEST['user_id']) ? '' : trim($_REQUEST['user_id']);
$filter['goods_stock'] = empty($_REQUEST['goods_stock']) ? '' : intval($_REQUEST['goods_stock']);
$filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'goods_stock' : trim($_REQUEST['sort_by']); // js的listTable.sort排序功能,也可以user_id
$filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
$ex_where = ' WHERE 1 ';
$ex_where .=" AND user_id = '$filter[user_id]' ";
$filter['record_count'] = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('depot') . $ex_where);
/* 分页大小 */
$filter = page_and_size($filter);
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('depot') . $ex_where .
" ORDER by " . $filter['sort_by'] . ' ' . $filter['sort_order'] .
" LIMIT " . $filter['start'] . ',' . $filter['page_size'];
// $filter['keywords'] = stripslashes($filter['keywords']);
set_filter($filter, $sql);
}
else
{
$sql = $result['sql'];
$filter = $result['filter'];
}
$depot_list = $GLOBALS['db']->getAll($sql);
foreach($depot_list as $k=>$v){
$sql = "SELECT goods_name,goods_thumb from ".$GLOBALS['ecs']->table('goods')." where goods_id = ".$v['goods_id'];
$re = $GLOBALS['db']->getRow($sql);
$depot_list[$k]['name'] = $re['goods_name'];
$depot_list[$k]['goods_thumb'] = $re['goods_thumb'];
}
$arr = array('depot_list' => $depot_list, 'filter' => $filter,
'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
return $arr;
}
2.写一个列表实例代码
elseif($_REQUEST['act'] == 'depot_log'){
$smarty->assign('ur_here', '个人微仓操作记录');
$depot = depot_log_list();
//print_r($depot);
$smarty->assign('depot_log', $depot['depot_list']);
$smarty->assign('filter', $depot['filter']);
$smarty->assign('record_count', $depot['record_count']);
$smarty->assign('page_count', $depot['page_count']);
$smarty->assign('full_page', 1);
assign_query_info();
$smarty->display('depot_log_list.htm');
}
3.写一个列表查询(这里的depot_log_query ,还可以承接html页面的<a href="javascript:listTable.sort('goods_stock', 'DESC'); ">)
/*会员微仓 ajax 翻页调用*/
elseif ($_REQUEST['act'] == 'depot_list_query'){
$depot = depot_list();
//$depot = user_list();
$smarty->assign('depot', $depot['depot_list']);
$smarty->assign('filter', $depot['filter']);
$smarty->assign('record_count', $depot['record_count']);
$smarty->assign('page_count', $depot['page_count']);
$sort_flag = sort_flag($depot['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
make_json_result($smarty->fetch('depot_list.htm'), '', array('filter' => $depot['filter'], 'page_count' => $depot['page_count'])); // 注意此处的结构,缺少mke_json_result不行
}
4.html页面html代码
<table cellpadding="3" cellspacing="1">
<tr>
<th width="80">
<input onclick='listTable.selectAll(this, "checkboxes")' type="checkbox">
{$lang.record_id}{$sort_user_id}
</th>
<th width="60">缩略图</th>
<th>商品名称</th>
<th><a href="javascript:listTable.sort('order_amount', 'DESC'); ">库存</a></th>
<th>{$lang.handler}</th>
<tr>
{foreach from=$depot item=vo}
<tr>
<td><input type="checkbox" name="checkboxes[]" value="{$vo.id}" notice="{if $user.user_money ne 0}1{else}0{/if}"/>{$vo.id}</td>
<td class="first-cell"><a href="../goods.php?id={$vo.id}" target="_blank"><img src="../{$vo.goods_thumb}" width=40 style="border: 1px solid #eee"/></a></td>
<td><span onclick="listTable.edit(this, 'edit_email', {$user.user_id})"><a href="../goods.php?id={$vo.id}" target="_blank">{$vo.goods_name}</a></span></td>
<td align="center">{$vo.goods_stock}</td>
<td align="center">
<a href="users.php?act=depot_log&user_id={$vo.user_id}&goods_id={$vo.goods_id}" title="查看记录"><img src="images/icon_view.gif" border="0" height="21" width="21" /></a>
</td>
</tr>
{foreachelse}
<tr><td class="no-records" colspan="11">{$lang.no_records}</td></tr>
{/foreach}
<tr>
<td colspan="2">
<input type="hidden" name="act" value="batch_remove" />
<input type="submit" id="btnSubmit" value="{$lang.button_remove}" disabled="true" class="button" /></td>
<td align="right" nowrap="true" colspan="9">
{include file="page.htm"}
</td>
</tr>
</table>
js代码
{if $full_page}
</div>
<!-- end users list -->
</form>
<script type="text/javascript" language="JavaScript">
<!--
listTable.recordCount = {$record_count};
listTable.pageCount = {$page_count};
{foreach from=$filter item=item key=key}
listTable.filter.{$key} = '{$item}';
{/foreach}
{literal}
onload = function()
{
//document.forms['searchForm'].elements['keyword'].focus();
// 开始检查订单
startCheckOrder();
//a.listtable.js默认是listTable.query="query",也就是order.php页面的elseif ($_REQUEST['act'] == 'query')
如果不想只想默认的$_REQUEST['act']=='query',就需要写上以下代码
listTable.query = "depot_list_query"; 默认载入使用(第一次点击列表)
}
/**
* 搜索用户
*/
function searchUser()
{
//listTable.filter['keywords'] = Utils.trim(document.forms['searchForm'].elements['keyword'].value);
listTable.filter['page'] = 1;
// b.与a作用一样
listTable.query = "depot_list_query"; 承接上一次查询条件
listTable.loadList();
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}
{/if}
如果改变了,默认的query查询;则a,b两处都不可以少分页实例化结构代码
Array
(
[depot_list] => Array
(
[0] => Array
(
[id] => 1
[user_id] => 1
[goods_id] => 2
[goods_stock] => 2
[goods_name] => 荷兰Nutrilon牛栏奶粉
)
[1] => Array
(
[id] => 7
[user_id] => 1
[goods_id] => 6
[goods_stock] => 4
[goods_name] => 1111
)
)
[filter] => Array
(
[user_id] => 1
[record_count] => 2
[page_size] => 4
[page] => 1
[page_count] => 1
[start] => 0
)
[page_count] => 1
[record_count] => 2
)
本文标签:
很赞哦! ()
相关文章
随机图文
-
ecshop商品添加一个30天销量随机30天虚拟销量的实现方法
ecshop添加一个30天销量,怎么自动显示随机30天虚拟销量修改教程做商城网站卖东西靠的是正品货真价实,但有时候的东西确实很好,就是没有销量,当看到当月销量为0时 -
ecshop搜索商品货号搜索商品属性货号的实现方法
ECSHOP商城支持商品名称关键字,商品货号关键字等搜索商品,但不能按属性货号搜索。属性货号是ecshop属性库存的识别号,建立属性库存后,属性货号保存在products表中 -
ecshop线下红包不能支持最小订单的解决方法
线下红包都有个bug,就是线下红包不支持很小订单,无论多小金额的订单都能使用红包。 -
ecshop如何修复数据表ecs_sessions.MYI报错
由于MySQL本身的读写及锁定机制等方面的原因,与一些其他数据库软件一样,在特殊情况下的极为频繁读写时,或在服务器掉电、死机等情况下
留言与评论 (共有 条评论) |