테스트 사이트 - 개발 중인 베타 버전입니다

회원아이디 검색 쿼리 질문 채택완료

웹프리존 11년 전 조회 7,570
현재는 검색을 하면 제목을 인식해서 출력 되는데요.
회원아이디 즉 sfl=mb_id,1&lstx=jamtty 이렇게 주소창에 불러 와서 출력물이  출력 되려면
아래 쿼리를 어떻게 수정해야 될까요 ..
$sql_common = " from {$g5['poll_table']} ";
$sql_search = " where (1) ";
if ($stx) {
    $sql_search .= " and ( ";
    switch ($sfl) {
        default :
            $sql_search .= " ({$sfl} like '%{$stx}%') ";
            break;
    }
    $sql_search .= " ) ";
}
if (!$sst) {
    $sst  = "po_id";
    $sod = "desc";
}
$sql_order = " order by {$sst} {$sod} ";
$sql = " select count(*) as cnt
            {$sql_common}
            {$sql_search}
            {$sql_order} ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$rows = $config['cf_page_rows'];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page < 1) $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함
$sql = " select *
            {$sql_common}
            {$sql_search}
            {$sql_order}
            limit {$from_record}, {$rows} ";
$result = sql_query($sql);
댓글을 작성하려면 로그인이 필요합니다.

답변 2개

채택된 답변
+20 포인트
리자
리자 Expert
11년 전
<div><span style="font-family: gulim, helvetica; line-height: 23.54400062561035px">$sql_search .= " ({$sfl} like '%{$stx}%') ";</span></div>
<div>
<span style="font-size: 10pt; line-height: 1.5"></span></div>
<div>list($field, $opt) = explode(',', $sfl);</div>
<div><span style="font-family: gulim, helvetica; line-height: 23.54400062561035px">$sql_search .= " ({$field} like '%{$stx}%') ";</span></div>
<div>
와 같이 수정해 보시기 바랍니다.
로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

11년 전
</strong></div>
<div>
<div style="font-family: gulim, helvetica; line-height: 23.54400062561035px">switch ($sfl) {</div>
<div style="font-family: gulim, helvetica; line-height: 23.54400062561035px">        default :</div>
<div style="font-family: gulim, helvetica; line-height: 23.54400062561035px">            $sql_search .= " ({$sfl} like '%{$stx}%') ";</div>
<div style="font-family: gulim, helvetica; line-height: 23.54400062561035px">            break;</div>
<div style="font-family: gulim, helvetica; line-height: 23.54400062561035px">    }</div></div>
<div style="font-family: gulim, helvetica; line-height: 23.54400062561035px"><strong style="font-family: 돋움, dotum, helvetica; font-size: 12px; line-height: 21.600000381469727px">
</strong></div>
<div>
<div style="font-family: gulim, helvetica; line-height: 23.54400062561035px">
<div>switch ($sfl) {</div>
<div>       </div>
<div>        case 'mb_id' :</div>
<div>            $sql_search .= " ({$sfl} = '{$stx}') ";</div>
<div>            break;</div>
<div><span class="Apple-tab-span" style="white-space: pre">		</span>default :</div>
<div>            $sql_search .= " ({$sfl} like '{$stx}%') ";</div>
<div>            break;</div>
<div>       </div>
<div>    }</div></div></div>
<div style="font-family: gulim, helvetica; line-height: 23.54400062561035px"><strong style="font-family: 돋움, dotum, helvetica; font-size: 12px; line-height: 21.600000381469727px">
이렇게 수정해서 해결되었습니다.
감사합니다.
로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

관리자
11년 전
$sfl = 'mb_id,1' 이기 때문에 where 조건에 넣으면 에러가 발생됩니다.
웹프리존
11년 전
$sfl = 'mb_id' 이렇게 검색해서 하게 되었어요 ~

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인