Skip to content
Advertisement

Search Engine Developement using MySQL relevancy, not working on PHP

i’m working on search engine developement. I’m kinda struggling with an SQL/PHP request. I’m trying to get the highest relevancy score from a search query. It works perfectly on SQL, but not at all on PHP, neither on localhost nor online (while the source code is generated by phpmyadmin itself).

    $connect = mysqli_connect('a', 'b','c','d');    
    $sql1 = "SELECT job, MATCH (job)  AGAINST ('sales representative' IN BOOLEAN MODE) AS score FROM general_comp ORDER BY score DESC limit 1";
    $result = mysqli_query($connect, $sql1); 

    echo $result;

Obviously SQL connection works, since other requests are working very well. Any idea ?

Source = https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html

Advertisement

Answer

You need to fetch the results from the resource $result:

$connect = mysqli_connect('a', 'b','c','d');    
$sql1 = "SELECT job, MATCH (job)  AGAINST ('sales representative' IN BOOLEAN MODE) AS score FROM general_comp ORDER BY score DESC limit 1";
$result = mysqli_query($connect, $sql1); 
$row = mysqli_fetch_assoc($result);
print_r($row);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement