Home > Database > Mysql Tutorial > Drupal A-Z and number filter

Drupal A-Z and number filter

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:40:02
Original
967 people have browsed it

在网站数据多的时候,很多都提供一个A到Z、数字的过滤显示,经常应用在产品列表中,用于分离、过滤按字母或者拼音开头的产品名称。 MYSQL 查询 A-Z的字母开头的字段值 SELECT * FROM MyTable WHERE MyColumn LIKE 'A%'; SELECT * FROM MyTable WHERE MyColum

在网站数据多的时候,很多都提供一个A到Z、数字的过滤显示,经常应用在产品列表中,用于分离、过滤按字母或者拼音开头的产品名称。

Drupal a-z filter and number filter

MYSQL 查询

A-Z的字母开头的字段值

SELECT * FROM MyTable WHERE MyColumn LIKE 'A%';<br> 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);
Copy after login

(...)
Read the rest of Drupal A-Z and number filter (1 words)


© Li Xi for LixiPHP, 2014. | Permalink | No comment | Add to del.icio.us
Post tags: A-Z, Drupal 6, Drupal7, filter, MySQL, number, REGEXP

Feed enhanced by Better Feed from Ozh

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template