这个问题我绕来绕去。自己都晕啦。。反正最后是实现了我需要的功能
用thinkphp做的:
源数据如下,我要统计里面的店铺出现的多少次,由于输出到模板是列表的形式,所以想在每个店铺后面输出一个统计数字。
效果如图:
[code lang=”php”]
array(6) {
[0] => array(16) {
["id"] => string(4) "3942"
["name"] => string(9) "shanmao.s"
["dctime"] => string(10) "1347465600"
["daytype"] => string(6) "晚餐"
["shop"] => string(17) "宝嘟嘟 Baodudu"
["food"] => string(12) "凉拌豆皮"
["tel"] => string(7) "2227019"
["price"] => string(1) "7"
["pack"] => string(0) ""
["many"] => string(1) "1"
["total"] => string(1) "7"
["exp"] => string(14) "不是加班, "
["note"] => NULL
["orderip"] => string(9) "127.0.0.1"
["ordertime"] => string(10) "1347509101"
["sid"] => string(3) "153"
}
[1] => array(16) {
["id"] => string(4) "3941"
["name"] => string(5) "admin"
["dctime"] => string(10) "1347465600"
["daytype"] => string(6) "午餐"
["shop"] => string(12) "一鸣瓦罐"
["food"] => string(6) "煨饭"
["tel"] => string(11) "15859253924"
["price"] => string(1) "1"
["pack"] => string(1) "0"
["many"] => string(1) "1"
["total"] => string(1) "1"
["exp"] => string(2) ", "
["note"] => NULL
["orderip"] => string(9) "127.0.0.1"
["ordertime"] => string(10) "1347501557"
["sid"] => string(3) "195"
}
[2] => array(16) {
["id"] => string(4) "3940"
["name"] => string(5) "admin"
["dctime"] => string(10) "1347465600"
["daytype"] => string(6) "午餐"
["shop"] => string(20) "新斯利美 Silimei"
["food"] => string(22) "鲜橙汁 orange juice"
["tel"] => string(7) "2202926"
["price"] => string(2) "12"
["pack"] => string(0) ""
["many"] => string(1) "1"
["total"] => string(2) "12"
["exp"] => string(2) ", "
["note"] => NULL
["orderip"] => string(9) "127.0.0.1"
["ordertime"] => string(10) "1347501541"
["sid"] => string(3) "137"
}
[3] => array(16) {
["id"] => string(4) "3939"
["name"] => string(5) "admin"
["dctime"] => string(10) "1347465600"
["daytype"] => string(6) "午餐"
["shop"] => string(21) "福品堂土楼小吃"
["food"] => string(9) "拌青菜"
["tel"] => string(7) "2027386"
["price"] => string(1) "3"
["pack"] => string(3) "0.5"
["many"] => string(1) "1"
["total"] => string(3) "3.5"
["exp"] => string(2) ", "
["note"] => NULL
["orderip"] => string(9) "127.0.0.1"
["ordertime"] => string(10) "1347499513"
["sid"] => string(3) "185"
}
[4] => array(16) {
["id"] => string(4) "3938"
["name"] => string(5) "admin"
["dctime"] => string(10) "1347465600"
["daytype"] => string(6) "午餐"
["shop"] => string(20) "新斯利美 Silimei"
["food"] => string(27) "珍珠奶茶 pearl milk tea"
["tel"] => string(7) "2202926"
["price"] => string(1) "6"
["pack"] => string(0) ""
["many"] => string(1) "1"
["total"] => string(1) "6"
["exp"] => string(2) ", "
["note"] => NULL
["orderip"] => string(9) "127.0.0.1"
["ordertime"] => string(10) "1347499501"
["sid"] => string(3) "137"
}
[5] => array(16) {
["id"] => string(4) "3937"
["name"] => string(5) "admin"
["dctime"] => string(10) "1347465600"
["daytype"] => string(6) "午餐"
["shop"] => string(20) "新斯利美 Silimei"
["food"] => string(27) "珍珠奶茶 pearl milk tea"
["tel"] => string(7) "2202926"
["price"] => string(1) "6"
["pack"] => string(0) ""
["many"] => string(1) "1"
["total"] => string(1) "6"
["exp"] => string(2) ", "
["note"] => NULL
["orderip"] => string(9) "127.0.0.1"
["ordertime"] => string(10) "1347499489"
["sid"] => string(3) "137"
}
}
[/code]
[code lang=”php”]
$olist=M()->query("SELECT `order`.*,`shop`.id as sid from `order` inner join `shop` on `shop`.shop = `order`.shop WHERE FROM_UNIXTIME(dctime,’%Y%m%d’)=$jint ORDER BY id desc LIMIT 40");
dump($olist);
$this->assign(‘zdlist’,$zdlist);
foreach($olist as $key => $val){
$vshop[] = $val[‘shop’];//找出每个店铺赋值到$vshop
}
$ac= array_count_values($vshop); //统计个数
$this->assign(‘ac’,$ac);//输出统计
$this->assign(‘zuijin’,$olist);//输出列表
[/code]
模板:
[code lang=”html”]
<volist name="zuijin" id="vo">有人点了:【<a href="__URL__/menu/id/{$vo.sid}">{$vo.shop}</a>】(<font style="color:red"><php>$shop = $vo[‘shop’]; echo $ac[$shop]</php></font>人点这家) 的{$vo.food}<br />
</volist>
[/code]
主要看这里:
[code lang=”html”]
<php>$shop = $vo[‘shop’]; echo $ac[$shop]</php>
[/code]
这算是一个笔记吧。