2009-09-28 2 views
0

PHP에서 mysql varchar로 단어를 어떻게 비교할 수 있습니까?
이 코드는 내가 원하는 무엇을 생산하지만,이 오류를PHP - 분해 된 단어를 PHP의 mysql varchar와 비교하십시오.

veranderenwachtwoordjij
치명적인 오류 제공 : 비 객체의 멤버 함수 fetch_assoc()를 호출합니다 ......

$word = "Also, to be safe, change your password regularly... you don't have to be obsessive about it: every three hours or so should be enough. And because erring on the side of caution is always a good idea, fake your own suicide and change your identity at least once a year."; 

$pieces = explode(" ", $word); 

$x = 0; 
while($x < word_count($word)) { // word count function returns int (51) 
    $aPiece = $pieces[$x]; // change $pieces[$x] to 'you' and then it works 
    $result = $conn->query("SELECT * FROM dict WHERE english='$aPiece'"); 

    $z = 0; 
    while($z < $num_result) // $num_result returns amount of rows in database 
    { 
    $row = $result->fetch_assoc(); //error line is here 
    echo stripslashes($row['dutch']); 
    $z++; 
    } 

    $x++; 
} 
+0

나는 PHP를 한 지 오래되었습니다. 그들은'for'-loop를 비난 했습니까? – Johnsyweb

답변

0

나는

$row = $result2->fetch_assoc();

가 있어야한다고 생각

$row = $result->fetch_assoc();

아무데도 $ 결과가없는 것 같아서.

+1

oops..it은 오타입니다 은 $ row = $ result-> fetch_assoc();이 (가)되어야합니다. – Azam

1

테스트 문에 don't에서 문제가 발생했다고 생각합니다. mysql_real_escape_string과 같은 기능으로 따옴표를 이스케이프하지 않았습니다. 예를 들어

: $

result2-에
$aPiece = mysql_real_escape_string($pieces[$x]); 
$result = $conn->query("SELECT * FROM dict WHERE english='$aPiece'"); 
0

$의 result2> fetch_assoc(); 올바른 변수, 그것은 당신이 당신의 데이터베이스에있는 단어를 찾기 위해 구두점을 삭제해야하는 방식으로

$result->fetch_assoc(); 

을해야되지 않은 첫 번째 라인 중 하나 (내 생각)해야합니다 (폭발하기 전에) 다음과 유사하십시오 :

$words = strtr($words, ',.:!',''); 
+0

이미 word_count 함수에서 해당 위치에 있습니다. :) – Azam