자동완성 검색기능 (결과값을 10개로 제한할 수 있나요?)
본문
위에 스크립트를 사용중인데요.
g5_popular 가 234,048 개입니다.
그러다 보니 18을 찍으면 수도없이 많이 나와서 문제입니다.
어떻게 하면 10개 또는 20개로 제한할 수 있을까요?
아래는 _search_popular.php 코드입니다.
도움 좀 주세요.
감사합니다.
p.s 될 수 있으면 가장 정확한 검색어가 출력되었으면 좋겠어요.
<?php
include_once('./_common.php');
$stx = $_GET['stx'];
$sql = "select
distinct(pp_word)
from
g5_popular
where
pp_word like '%".$stx."%'
group by
pp_word
order by
pp_word asc ";
$result = sql_query($sql,true);
// value : 검색된 단어이며, input 값으로 넘어갑니다.
// label : 특정검색어를 입력시 자동완성 리스트로 표시됩니다. (다양하게 응용가능)
while($row=sql_fetch_array($result)) {
$arr[] = array(
"value" => $row['pp_word'],
"label" => $row['pp_word']
);
}
echo json_encode($arr);
?>
답변 1
$sql = "select
distinct(pp_word)
from
g5_popular
where
pp_word like '%".$stx."%'
group by
pp_word
order by
pp_word asc limit 10 ";