select min(online) as onlinenum from tb_log_online where left(time,10)= '".substr($fromTime1,0,10)."'
截取时间段的左前十位
解决中文被截成乱码的问题
以下是代码片段:
function left(?$str, ?$len) { //解决中文被截成乱码的问题
?$arr = str_split(?$str);
?$i = 0;
foreach (?$arr as ?$chr) {
if (ord(?$chr) > 128)
?$add = ?$add ? 0 : 1;
?$i++;
if (?$i == ?$len)
break;
}
return substr(?$str, 0, ?$len + ?$add);
}
$addsql.="where 1=1";
$fromTime && $addsql .= " and ctime>='$fromTime'";
&&运算机制:如果 $fromTime为真,执行$addsql,得到$addsql=where 1=1 and ctime>='$fromTime'
如果$fromTime为假,不再执行
以上代码=
$addSql .= $fromTime ? " and `time`> = $fromTime" : ""; 三目运算:
¥sql语句分析:实现了按照三种类型排序的功能
public static function topN($orderType,$top){
if(!$orderType) return false;
if(!$top) $top = 10 ;
$types = array('user_credit', 'user_wenxun','user_wuxun');
$orderType = trim($orderType); if(!in_array($orderType,$types)) return false;
$sql="select user_id,user_name,user_character,user_countryID,user_uri,user_gold,user_point,user_credit,user_wenxun,user_wuxun,user_jsjqd from tb_user where `user_character`!='' ".
"order by $orderType desc limit 0,$top";