首页 > 技术文章 > 微擎语法实例

xiong-hua 原文

$condition = ' and uniacid = :uniacid and deleted=0';
$params = array(':uniacid' => $_W['uniacid']);

$pindex = max(1, intval($_GPC['page']));
$psize = 20;

//查询表中的所有数据
$list = pdo_fetchall("SELECT * FROM " . tablename('ewei_shop_perm_role'). ('WHERE 1 '.$condition. 'ORDER BY id desc LIMIT').($pindex - 1)* $psize ',' .$psize .$params);
//统计每个角色下面有几个人
foreach ($list as &$row)
{
$row['usercount'] = pdo_fetchcolum('select count(*) from '. tablename('ewei_shop_perm_user') . 'where roleid=:roleid limit 1',array(':roleid' =>$row['id']));
}
//统计角色表里共有多少个角色
$total = pdo_fetchcolumn('SELECT count(*) FROM ' . tablename('ewei_shop_perm_role') . ('  WHERE 1 ' . $condition . ' '), $params);
//更新语句
$data = array('uniacid' => $_W['uniacid'],'rolename' =>trim($_GPC['rolename']),'status' =>intval($_GPC['status']),'perms2' =>trim($_GPC['permsarray']));
pdo_update('ewei_shop_perm_role',$data,array('id' =>$id,'uniacid' =>$_W['uniacid']));
//插入语句
pdo_insert('ewei_shop_perm_role',$data);
//展示模板
include $this->template();
include $this->template('role.html');
//删除语句
$items = pdo_fetchall('SELECT id,rolename FROM ' . tablename('ewei_shop_perm_role') . ('WHERE id in ('. $id .' ) AND uniacid=') .$_W['uniacid'])

foreach ($items as $item) {
pdo_delete('ewei_shop_perm_role',array('id' => $item['id']));
plog('perm.role.delete','删除角色 ID:' .$item['id'] . '角色名称: ' .$item['rolename'] . '');
}




世界上最美的风景,是自己努力的模样

推荐阅读