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

search.php 파일 문의 채택완료

아기강도 6년 전 조회 3,487

안녕하세요.

 

통합검색에 여분필드를 포함하고자 합니다

 

중간에 잘 모르는 부분 이 있어 코드문의드립니다.

 

</p>

<div style="color: rgb(212, 212, 212); line-height: 19px; font-family: Consolas, "Courier New", monospace; font-size: 14px; font-weight: normal; white-space: pre; background-color: rgb(30, 30, 30);">
<div><span style="color: rgb(212, 212, 212);">        </span><span style="color: rgb(106, 153, 85);">// 필드의 수만큼 다중 필드 검색 가능 (필드1+필드2...)</span></div>

<div><span style="color: rgb(212, 212, 212);">        </span><span style="color: rgb(197, 134, 192);">for</span><span style="color: rgb(212, 212, 212);"> (</span><span style="color: rgb(156, 220, 254);">$k</span><span style="color: rgb(212, 212, 212);">=</span><span style="color: rgb(181, 206, 168);">0</span><span style="color: rgb(212, 212, 212);">; </span><span style="color: rgb(156, 220, 254);">$k</span><span style="color: rgb(212, 212, 212);"><</span><span style="color: rgb(220, 220, 170);">count</span><span style="color: rgb(212, 212, 212);">(</span><span style="color: rgb(156, 220, 254);">$field</span><span style="color: rgb(212, 212, 212);">); </span><span style="color: rgb(156, 220, 254);">$k</span><span style="color: rgb(212, 212, 212);">++) {</span></div>

<div><span style="color: rgb(212, 212, 212);">        </span></div>

<div><span style="color: rgb(212, 212, 212);">            </span><span style="color: rgb(156, 220, 254);">$str</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(212, 212, 212);">.=</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(156, 220, 254);">$op2</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">            </span><span style="color: rgb(197, 134, 192);">switch</span><span style="color: rgb(212, 212, 212);"> (</span><span style="color: rgb(156, 220, 254);">$field</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(156, 220, 254);">$k</span><span style="color: rgb(212, 212, 212);">]) {</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">case</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">'mb_id'</span><span style="color: rgb(212, 212, 212);"> :</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">case</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">'wr_name'</span><span style="color: rgb(212, 212, 212);"> :</span></div>

<div><span style="color: rgb(212, 212, 212);">                    </span><span style="color: rgb(156, 220, 254);">$str</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(212, 212, 212);">.=</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">"</span><span style="color: rgb(156, 220, 254);">$field</span><span style="color: rgb(206, 145, 120);">[</span><span style="color: rgb(156, 220, 254);">$k</span><span style="color: rgb(206, 145, 120);">] = '</span><span style="color: rgb(156, 220, 254);">$s</span><span style="color: rgb(206, 145, 120);">[</span><span style="color: rgb(156, 220, 254);">$i</span><span style="color: rgb(206, 145, 120);">]'"</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">                    </span><span style="color: rgb(197, 134, 192);">break</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">case</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">'wr_subject'</span><span style="color: rgb(212, 212, 212);"> :</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">case</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">'wr_content'</span><span style="color: rgb(212, 212, 212);"> :  </span></div>

<div><span style="color: rgb(212, 212, 212);">                    </span><span style="color: rgb(197, 134, 192);">if</span><span style="color: rgb(212, 212, 212);"> (</span><span style="color: rgb(220, 220, 170);">preg_match</span><span style="color: rgb(212, 212, 212);">(</span><span style="color: rgb(209, 105, 105);">"/[a-zA-Z]/"</span><span style="color: rgb(212, 212, 212);">, </span><span style="color: rgb(156, 220, 254);">$search_str</span><span style="color: rgb(212, 212, 212);">)){</span></div>

<div><span style="color: rgb(212, 212, 212);">                        </span><span style="color: rgb(156, 220, 254);">$str</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(212, 212, 212);">.=</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">"INSTR(LOWER({</span><span style="color: rgb(156, 220, 254);">$field</span><span style="color: rgb(206, 145, 120);">[</span><span style="color: rgb(156, 220, 254);">$k</span><span style="color: rgb(206, 145, 120);">]}), LOWER('{</span><span style="color: rgb(156, 220, 254);">$search_str</span><span style="color: rgb(206, 145, 120);">}'))"</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">                    }</span><span style="color: rgb(197, 134, 192);">else</span><span style="color: rgb(212, 212, 212);">{</span></div>

<div><span style="color: rgb(212, 212, 212);">                        </span><span style="color: rgb(156, 220, 254);">$str</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(212, 212, 212);">.=</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">"INSTR({</span><span style="color: rgb(156, 220, 254);">$field</span><span style="color: rgb(206, 145, 120);">[</span><span style="color: rgb(156, 220, 254);">$k</span><span style="color: rgb(206, 145, 120);">]}, '{</span><span style="color: rgb(156, 220, 254);">$search_str</span><span style="color: rgb(206, 145, 120);">}')"</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">                    }</span></div>

<div><span style="color: rgb(212, 212, 212);">                    </span><span style="color: rgb(197, 134, 192);">break</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">case</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">'com_subnote'</span><span style="color: rgb(212, 212, 212);"> :</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">case</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">'com_addr1'</span><span style="color: rgb(212, 212, 212);"> :</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">case</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">'com_cate1'</span><span style="color: rgb(212, 212, 212);"> :</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">case</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">'com_cate2'</span><span style="color: rgb(212, 212, 212);"> :</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(197, 134, 192);">default</span><span style="color: rgb(212, 212, 212);"> :</span></div>

<div><span style="color: rgb(212, 212, 212);">                        </span><span style="color: rgb(156, 220, 254);">$str</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(212, 212, 212);">.=</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(206, 145, 120);">"1=0"</span><span style="color: rgb(212, 212, 212);">; </span><span style="color: rgb(106, 153, 85);">// 항상 거짓</span></div>

<div><span style="color: rgb(212, 212, 212);">                        </span><span style="color: rgb(197, 134, 192);">break</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">                }</span></div>

<div><span style="color: rgb(212, 212, 212);">                </span><span style="color: rgb(156, 220, 254);">$op2</span><span style="color: rgb(212, 212, 212);"> = </span><span style="color: rgb(206, 145, 120);">" or "</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">        </span></div>

<div><span style="color: rgb(212, 212, 212);">            }</span></div>
</div>

<p>

 

해당 코드에서 INSTR 부분이 사용될때와 사용하지 않을때 차이가 무었인지 궁금합니다.

여분필드를 아래에 추가하였는데 case문만 추가하여도 되는지요..

 

참고는 http://gnustudy.com/bbs/board.php?bo_table=skin_etc&wr_id=27">http://gnustudy.com/bbs/board.php?bo_table=skin_etc&wr_id=27 를 참고하였습니다.

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

답변 1개

채택된 답변
+20 포인트
Policia
6년 전

com_subnote, com_addr1, com_cate1, com_cate2 이부분이 작성자분께서 추가하신거죠?

 

저렇게 연결해놓으면 default와 연결되어서 위 필드로 검색시 default로 연결됩니다 즉 항상 거짓이게 되버려서 검색결과는 아무것도 안나오게 되겠지요

 

위 부분을 wr_content 밑쪽에다가 붙여보세요

 

INSTR는 INSTR(필드, 검색어)해서 필드에서 해당 검색어가 포함된 결과값을 알려줍니다

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

아기강도
6년 전
말씀해주신대로 추가내용위치를 옴겼습니다!
조언 감사합니다!^^

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

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

로그인