MySQL sort by Field Value

Source: Internet
Author: User

1. MySQL is sorted by the first letter of the pinyin Field Value

Keywords binary: selectName from topic order bybinary name ASC

 

2. Obtain the first letter of Chinese pinyin in PHP.

Directly call the following function. For example, Echo getinitial ("Dan ");

Function getinitial ($ Str)
{
   $ ASC = ord (substr ($ STR, 0, 1 ));
   If ($ ASC <160) // non-Chinese
   {
       If ($ ASC >=48 & $ ASC <= 57 ){
           Return '1 ';// Number
       } Elseif ($ ASC >=65 & $ ASC <= 90 ){
           Return CHR ($ ASC ); // A--Z
       } Elseif ($ ASC >=97 & $ ASC <= 122 ){
           Return CHR ($ asc-32); // A -- Z
       } Else {
           Return '~ '; // Others
       }
   }
   Else // Chinese
   {
       $ ASC = $ ASC * 1000 + ord (substr ($ STR, 1, 1 ));
       // Get the first letter A--Z of Pinyin
       If ($ ASC> = 176161 & $ ASC <176197 ){
           Return 'a ';
       } Elseif ($ ASC >=176197 & $ ASC <178193 ){
           Return 'B ';
       } Elseif ($ ASC >=178193 & $ ASC <180238 ){
           Return 'C ';
       } Elseif ($ ASC >=180238 & $ ASC <182234 ){
           Return 'D ';
       } Elseif ($ ASC >=182234 & $ ASC <183162 ){
           Return 'E ';
       } Elseif ($ ASC >=183162 & $ ASC <184193 ){
           Return 'F ';
       } Elseif ($ ASC >=184193 & $ ASC <185254 ){
           Return 'G ';
      

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.