Searching with MATCH(), AGAINST() and AS score with mysqli and php

Posted by Drew on Stack Overflow See other posts from Stack Overflow or by Drew
Published on 2010-04-06T14:22:07Z Indexed on 2010/04/06 19:03 UTC
Read the original article Hit count: 266

Filed under:
|
|

Below is the code I am using to search my table. I have made the relevant columns FULLTEXT in the table. This doesn't return me anything. Can someone tell me what it is that i'm doing wrong? Thanks in advance.

$sql = 'SELECT id,uname,class,school, MATCH(uname, class, school) AGAINST(?) AS score FROM images WHERE MATCH(uname, class, school) AGAINST(? IN BOOLEAN MODE) ORDER BY score DES';

$stmt = $db_connection->prepare($sql);

$stmt->bind_param('ss',$keyword,$keyword);

$stmt->execute();

$stmt->store_result();
$stmt->bind_result($id,$uname,$class,$school);

$xml = "<data>".PHP_EOL;

while($stmt->fetch()){

    $xml .= "   <person>".PHP_EOL;
    $xml .= "       <id>$id</id>".PHP_EOL;
    $xml .= "       <name>$uname</name>".PHP_EOL;
    $xml .= "       <class>$class</class>".PHP_EOL;
    $xml .= "       <school>$school</school>".PHP_EOL;
    $xml .= "   </person>".PHP_EOL;

}

$xml .= "</data>";

echo $xml;

Below is an image of the indexes of the table: alt text

© Stack Overflow or respective owner

Related posts about php

Related posts about mysqli