php 从 mysql 中选择,其中标题以 A 开头(并且只有 A)
我确信这非常简单,但似乎无法弄清楚。我需要从我的数据库中选择所有标题以 A、B 或 C 等开头的标题。这是我尝试过的远:
SELECT * FROM weblinks WHERE catid = 4 AND title LIKE 'A'
但什么也没返回..有人可以帮我解决这个问题吗?
干杯
I'm sure this is super easy, but can't seem to figure it out.. I need to select all titles from my database where the title starts with A, or B, or C etc. Here's what I've tried so far:
SELECT * FROM weblinks WHERE catid = 4 AND title LIKE 'A'
but returns nothing.. Could someone help me out with this?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于以“A”开头的标题,请在
A
后使用%
对于其中包含字母“A”的标题,请在两侧使用
%
A
对于以字母“A”结尾的标题,请在
A
之前使用%
基本上
%
是通配符。它告诉 MySQL 该位置中可以包含任何内容。要将数字作为第一个字母,请查看 马克的回答。
For titles starting in 'A' use a
%
after theA
For titles with the letter 'A' in it, use
%
on either side ofA
For titles ending in the letter 'A', use
%
before theA
Basically
%
is a wildcard. It tells MySQL that anything can be in the location.For having numbers as the first letter, check out Mark's answer.
LIKE
的通配符为%
和_
,其中 % 匹配 0 个或多个字符,_ 恰好匹配 1 个字符。The wildcards for
LIKE
are%
and_
, where % matches 0 or more characters and _ matches exactly one character.对于以 A 开头的现有答案是正确的:
对于以任何数字开头,您可以使用 REGEXP 运算符:
The existing answers are correct for beginning with A:
For beginning with any number you can use the REGEXP operator:
尝试:
依此类推
try:
so on and so forth
SELECT * FROM weblinks WHERE catid = 4 AND title LIKE 'A%'
% 表示“任何内容”,因此它是“A”然后是任何内容。仅适用于 LIKE 比较运算符。
SELECT * FROM weblinks WHERE catid = 4 AND title LIKE 'A%'
% tells "anything", so it's "A" then anything. Only works with the LIKE comparison operator.