微擎sql语句 or and where 拼接方法 分页 实现方法
微擎sql语句 or and where 拼接方法 分页 实现方法
$pindex = max(1, intval($_GPC['page']));
$psize = 20;
$status = intval($_GPC['status']);
$where = " weid = '{$_W['uniacid']}' AND from_user = '{$_W['fans']['from_user']}'";
if ($status == 2) {
$where.=" and ( status=1 or status=2 )";
} else {
$where.=" and status=$status";
}
$list = pdo_fetchall("SELECT * FROM " . tablename('js_sc_order') . " WHERE $where ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize, array(), 'id');
$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('js_sc_order') . " WHERE weid = '{$_W['uniacid']}' AND from_user = '{$_W['fans']['from_user']}'");
$pager = pagination($total, $pindex, $psize);
if (!empty($list)) {
foreach ($list as &$row) {
$goodsid = pdo_fetchall("SELECT goodsid,total FROM " . tablename('js_sc_order_goods') . " WHERE orderid = '{$row['id']}'", array(), 'goodsid');
$goods = pdo_fetchall("SELECT g.id, g.title, g.thumb, g.unit, g.marketprice,o.total,o.optionid FROM " . tablename('js_sc_order_goods') . " o left join " . tablename('js_sc_goods') . " g on o.goodsid=g.id "
. " WHERE o.orderid='{$row['id']}'");
foreach ($goods as &$item) {
//属性
$option = pdo_fetch("select title,marketprice,weight,stock from " . tablename("js_sc_goods_option") . " where id=:id limit 1", array(":id" => $item['optionid']));
if ($option) {
$item['title'] = "[" . $option['title'] . "]" . $item['title'];
$item['marketprice'] = $option['marketprice'];
}
}
unset($item);
$row['goods'] = $goods;
$row['total'] = $goodsid;
$row['dispatch'] = pdo_fetch("select id,dispatchname from " . tablename('js_sc_dispatch') . " where id=:id limit 1", array(":id" => $row['dispatch']));
}
}