简体   繁体   English

如何仅检查来自mysql单元的前两个字母?

[英]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.

相关问题 如何只在PHP中获得大写的首字母? - How to get only the uppercase first letters in PHP? 如何检查两个字符串是否包含相同的字母? - How to check if two strings contain the same letters? 如何检查字符串在PHP中是否仅包含字母? - How to check if a string contains only letters in PHP? 如何从PHP的MySQL中检查某个单元格是否等于0? - How can I check If a certain cell is equal to 0 in MySQL from PHP? 如何用PHP从MySQL表中只检索一个单元格 - How to retrive only one cell from MySQL table with PHP MySQL更新(来自PHP)-仅运行前几行。一次更新后,Alls CELL被锁定 - Mysql UPDATE (from PHP) - only runs first few rows.. Alls CELL locked after one UPDATE 从两个单词的字符串中获取第一个字母(PHP - 最快的方式) - Get first letters from a string of two words (PHP - fastest way) 如何获得子字符串,直到前两个连续的大写字母(但不包括这两个字母) - How to get substring up until first two consecutive capital letters (but not including those two letters) 匹配前两个单词的前两个字母 - matching first two letters of the first two words 检查一个单词是否有多个大写字母,只更改只有一个大写的单词(并且是第一个字母) - Check if a word has multiple uppercases letters and only change the words who have One and only uppercase (and be the first letter )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM