今天帮别人改个东西,当时mysql数据库设计的有点问题,一行列里每个数字你都带了万,但又要用到这行的数字比较查询。
先百度转下别人的
文本处理函数
函数 | 说明 |
Concat(t1,t2,....) | 连接字符串 |
Concat_ws(s,t1,t2.....) | 返回t1st2的字符串 |
Left(t,y) | 返回串t左边y个的字符 |
Right(t,y) | 返回串t右边y个的字符 |
Length(t) | 返回串t的长度 |
Lower(t) | 将串转换为小写 |
Upper(t) | 将串转换为大写 |
LTrim() | 去掉串左边的空格 |
RTrim() | 去掉右边的空格 |
Trim(t) | 去掉左右两边的空格 |
Replace(t1,t2,t3) | 把t1字符串中的t2换为t3 |
SubString(t,x,y) | 返回t中始于x的y个字符的串 |
Select concat(firstname,’’,lastname) from users;
Select concat(firstname,’’,lastname) as name from users;
Select length(firstname) as name_length from users;
数值处理函数
函数 | 说明 |
Abs() | 返回一个数的绝对值 |
Cos() | 返回一个角度的余弦 |
Exp() | 返回一个数的指数值 |
Mod() | 返回除操作的余数 |
Pi() | 返回圆周率 |
Pow(n1,n2) | N1的n2次方 |
Rand() | 返回一个随机数 |
Round(n1,n2) | 返回数n1,它被四舍五入为n2位小数 |
Sin() | 返回一个角度的正弦 |
Sqrt() | 返回一个数的平方根 |
Tan() | 返回一个角度的正切 |
Ceiling(n) | 基于n的值的下一个最大的整数 |
Floor | 返回n的整数值 |
Format(n1,n2) | 返回格式化为一个数的n1,这个数带有n2位小数,并且每3位之间插入一个逗号 |
在直接上代码吧,懒得打字。哎。thinkphp代码片段
$area = I("get.area"); //价格
/*第4部,按价格查询*/
if(!empty($area)){
$patterns = "/\d+/";
$areatab = array();
preg_match_all($patterns,$area,$areatab);
//var_dump(count($areatab[0]) );
if(count($areatab[0]) == 1){
if(strpos($area, "以上")){
$begtxt = $areatab[0][0];
$condition['_string'] = " FLOOR( REPLACE( attrPrice, '万', '' ) ) > $begtxt";
} else {
$endtxt = $areatab[0][0];
$condition['_string'] = " FLOOR( REPLACE( attrPrice, '万', '' ) ) < $endtxt";
}
}elseif (count($areatab[0]) == 2) {
$begtxt = $areatab[0][0];
$endtxt = $areatab[0][1];
$condition['_string'] = " FLOOR( REPLACE( attrPrice, '万', '' ) ) > $begtxt and FLOOR( REPLACE( attrPrice, '万', '' ) ) < $endtxt";
}
}
$count = $goods->where($condition)->count();
$con = 20 ; //每页数量
$page = new \Component\Page($count,$con);// 实例化分页类 传入总记录数和每页显示的记录数
$display=array(3,4,6); //显示样式
$pagehtml = $page->fpage($display); //获取页码列表
//详情
$list = $goods->Where($condition)->Order('nosort,id desc')->limit(($page->page-1)*$con.", $con")->Select();
$this->assign('list', $list); //详情列表
$this->assign('pageshow',$pagehtml); //分页页面