在网站数据多的时候,很多都提供一个a到z、数字的过滤显示,经常应用在产品列表中,用于分离、过滤按字母或者拼音开头的产品名称。
mysql 查询a-z的字母开头的字段值
select * from mytable where mycolumn like 'a%';
select * from mytable where mycolumn like 'z%';
数字开头的字段值
select * from mytable where mycolumn regexp '^[0-9]';
drupal 7 sql查询a-z的字母开头的字段值
db_select(‘mytable’)->condition(‘mycolumn’,?$alpha.’%', ‘like’);
数字开头的字段值
db_select(‘mytable’)->condition(‘mycolumn’, ‘^[0-9]‘, ‘regexp’);
drupal 6 sql % 转义在drupal 6中直接使用sql查询,但是注意%需要用%%来转义,意思就是在sql中:
%% 代表 %
%s 代表 字符串的占位符
例如:
db_query(select mycolumn from mytable where mycolumn='%s' and title like '%%%s%%', $column, $tile);
(...)
read the rest of drupal a-z and number filter (1 words)
© li xi for lixiphp, 2014. |permalink |no comment |add todel.icio.us
post tags: a-z, drupal 6, drupal7, filter, mysql, number, regexp
feed enhanced by better feed from ozh
