2014-05-20 2 views
0

데이터베이스에 게시 된 기사에 대한 php 아약스 검색을하려고하는데, 결과 만 표시됩니다. 필자는 데이터베이스와 select 쿼리에 대한 연결을 테스트했으며 작동합니다.php 아약스 검색 결과에 표시되지 않습니다

<?php 
require_once('dbconn.php'); 
$s = $_GET["s"]; 
$livesearch = ''; 
if (strlen($s) > 0) 

{ 
    $result = mysql_query("select * from articles where art_sts='1' ORDER BY title"); 
    if ($result != FALSE) 
    { 
     foreach($result as $row) 
     { 
      if (stristr($row['title'], $s)) 
      { 
       if ($livesearch == '') 
       { 
        $livesearch = '<a href="upload_pdf/'.$row["fisier"].'?id='.$row["id"].' "> '.htmlentities($row["title"], ENT_QUOTES, "UTF-8").'</a>'; 
       } 
      } 
     } 
    } 

} 

if ($livesearch == '') 
{ 
    $respond="No results..."; 
} 
else 
{ 
$respond = $livesearch; 
} 
echo $respond; 
?> 
+0

'$ result'는 리소스입니다. '$ result'에서 데이터를 가져와야합니다. 다음과 같은 것 :'while ($ row = mysql_fetch_assoc ($ result)) {...}'. – showdev

+1

새로운 개발에 mysql_ 함수를 사용해서는 안됩니다. 그들은 비추천입니다. 이제 PDO로 업그레이드 할 수 있습니다. – developerwjk

답변

1

당신은 실제로 당신이 출력하고자하는 데이터를 가져 havent 한 : 이 코드입니다. 다음과 같은 것을 추가해야합니다 ...

while($row = mysql_fetch_assoc($result)) { 
    if (stristr($row['title'], $s)) 
     { 
      if ($livesearch == '') 
      { 
       $livesearch = '<a href="upload_pdf/'.$row["fisier"].'?id='.$row["id"].' "> '.htmlentities($row["title"], ENT_QUOTES, "UTF-8").'</a>'; 
      } 
     } 
} 
+1

감사합니다. @Becs Carter! – user3658718

관련 문제