[英]How to check only the first two letters from a mysql cell?
I want to check a row in an mysql table for the username in php, if the username starts with ab to write an text. 如果用户名以ab开头以编写文本,我想在mysql表中的一行中查找php中的用户名。
the username is in a cell and looks like this: ab_12345453. 用户名位于一个单元格中,如下所示:ab_12345453。
Thanks, Sebastian 谢谢塞巴斯蒂安
EDIT: 编辑:
thank you all for your reply. 谢谢大家的答复。 but i need something else.
但我还需要其他东西。 i need this for joomla, i don't need to make an query, i just use:
$user->username
and i get the logged in username. 我需要joomla这个,我不需要查询,我只使用:
$user->username
,我得到了登录的用户名。
so i have the logged in username in a variable. 所以我有一个变量登录用户名。 how can i check that the username starts with ab_ ?
如何检查用户名以ab_开头?
thank you again and sorry for the confusion :( 再次感谢您,对不起您的困惑:(
SELECT * FROM bar B where B.username LIKE 'ab%';
请参阅此处的手册。
使用带有单个%通配符的LIKE命令说出任意字符
SELECT * FROM table WHERE col LIKE 'ab%';
I vote for Artefacto's solution, and add to it a recommendation: 我投票赞成Artefacto的解决方案,并向其提出建议:
alter table bar add key(username(2));
In case you don't have an index for the column. 如果您没有该列的索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.