[MySQL] 초성 검색 쿼리 (PHP 예) > db

본문 바로가기

db

[MySQL] 초성 검색 쿼리 (PHP 예)

페이지 정보

작성자 서방님 댓글 0건 조회 29회 작성일 12-05-23 10:32

본문

자소 분리된 한글 초성값($str)으로 mySQL 질의를 통해 결과를 얻어낼 수 있는 PHP 예제입니다.

 

switch ($str)
{
        case 'ㄱ':
                $qry = "and (title RLIKE '^(ㄱ|ㄲ)' OR ( title >= '가' AND title < '나' )) order by title";
                break;
        case 'ㄴ':
                $qry = "and (title RLIKE '^ㄴ' OR ( title >= '나' AND title < '다' )) order by title";
                break;
        case 'ㄷ':
                $qry = "and (title RLIKE '^(ㄷ|ㄸ)' OR ( title >= '다' AND title < '라' )) order by title";
                break;
        case 'ㄹ':
                $qry = "and (title RLIKE '^ㄹ' OR ( title >= '라' AND title < '마' )) order by title";
                break;
        case 'ㅁ':
                $qry = "and (title RLIKE '^ㅁ' OR ( title >= '마' AND title < '바' )) order by title";       
                break;
        case 'ㅂ':
                $qry = "and (title RLIKE '^ㅂ' OR ( title >= '바' AND title < '사' )) order by title";
                break;
        case 'ㅅ':
                $qry = "and (title RLIKE '^(ㅅ|ㅆ)' OR ( title >= '사' AND title < '아' )) order by title";
                break;
        case 'ㅇ':
                $qry = "and (title RLIKE '^ㅇ' OR ( title >= '아' AND title < '자' )) order by title";
                break;
        case 'ㅈ':
                $qry = "and (title RLIKE '^(ㅈ|ㅉ)' OR ( title >= '자' AND title < '차' )) order by title";
                break;
        case 'ㅊ':
                $qry = "and (title RLIKE '^ㅊ' OR ( title >= '차' AND title < '카' )) order by title";
                break;
        case 'ㅋ':
                $qry = "and (title RLIKE '^ㅋ' OR ( title >= '카' AND title < '타' )) order by title";
                break;
        case 'ㅌ':
                $qry = "and (title RLIKE '^ㅌ' OR ( title >= '타' AND title < '파' )) order by title";
                break;
        case 'ㅍ':
                $qry = "and (title RLIKE '^ㅍ' OR ( title >= '파' AND title < '하' )) order by title";
                break;
        case 'ㅎ':
                $qry = "and (title RLIKE '^ㅎ' OR ( title >= '하')) order by title";
                break;
        default:
                $qry = "order by title";
}

$qry = "select * from your_table where {$qry}";
$result = mysql_query($qry);

댓글목록

등록된 댓글이 없습니다.

Total 447건 1 페이지
게시물 검색

회원로그인

접속자집계

오늘
226
어제
282
최대
592
전체
37,324

그누보드5
Copyright © seobangnim.com All rights reserved.
자바스크립트를 활성화 하세요![ 브라우저에서 자바스크립트를 활성화하는 방법 ]