1.20
在js中取到select中的选中值value
$('#types').combobox('getValue')
多表查询(.列)
SELECT e.name,e.sal,d.dname FROM emp e, dept d WHERE e.deptno=d.deptno order by d.deptno;
在TP框架中引用原生sql语句(关键词query())
$sql="select * from zx_recharge r where r.uid_dc='0'"; $datas=M('recharge')->query($sql);
将数据库中的时间戳以时间的格式读取出来(将名为unixtime的字段的数据转换为日期格式并取别名为datetime)
select *,from_unixtime(unixtime,'%Y-%m-%d') as datetime from goods
写过的最长的sql语句(sql where语句中使用别名为判断条件)
//将名为paytime的字段的数据转换为日期格式并取别名为datetime //$sql="select *,from_unixtime(paytime,'%Y-%m-%d') as datetime from zx_recharge"; //获取12个月到现在的数据 //$sqla="select * from zx_recharge where DATE_FORMAT(datetime,'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m');"; //where使用别名为判断条件 //select t2.* from (select id, (c1 + c2) as c from t1) t2 where c > 100 $sqlb="select zx_recharge.* from (select *,from_unixtime(paytime,'%Y-%m-%d') as datetime from zx_recharge) zx_recharge where DATE_FORMAT(datetime,'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')"; $datab=M('recharge')->query($sqlb);
循环根据某一条件进行分组
$re = array(); foreach($arr as $v){ $re[$v['class']][] = $v['name']; } var_dump($re);
TP框架中截取字符串(关键词substr(变量名,开始截取位置,截到哪个位置))
foreach($datab as $v){ $str=$v['datetime']; $stra=substr($str,0,7); $re[$stra][] = $v['money']; }
1.23
//近12个月的用户充值统计 开始 //获取12个月到现在的数据 $sql="select zx_recharge.* from (select *,from_unixtime(paytime,'%Y-%m-%d') as datetime from zx_recharge) zx_recharge where DATE_FORMAT(datetime,'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')"; $datab=M('recharge')->query($sql); //过去12个月中每个月money列的数据之和 foreach($datab as $v){ $str=$v['datetime']; $stra=substr($str,0,7); $re[$stra][] = $v['money']; } foreach($re as $k=>$v){ foreach($v as $vv){ $attr[$k]+=$vv; } $xaxisvs[]=$k; } foreach($attr as $v){ $yaxisvs[]=$v; } //近12个月的用户充值统计 结束