0

我正在为一个 android 应用程序制作一个搜索引擎,该应用程序在布尔模式下对多个列进行全文搜索并匹配 '+word1 +word2'。但是,我无法获得任何搜索结果。

例如搜索字段类型-“open sea”然后,Sql 将搜索 Match...Against ('+open +sea' IN BOOLEAN MODE)

并显示可选结果列表,单击每个结果后,将在新页面上提供特定结果的详细信息。

对不起,我是android应用程序开发的新手。

这是我的 search.php 的 php 代码

<?php

 @ $db = new mysqli('localhost','username','password','db');

  if (mysqli_connect_errno()) {
     echo 'Error: Could not connect to database.  
     Please try again later.';
     exit;
  }

if(!empty($_POST)){

     $term = $_POST['query'];

    $words = explode(" ", trim($term));
    $termArray = array();
    foreach($words as $word){
        if(!empty($word)){
            $termArray[] = "+$word";
                         }
                }
    $searchquery = implode(" ", $termArray);

  if (!$term) {
     echo 'You have not entered any search details. Please go back and try again.';
     exit;
    }
    //initial query

    $query = "SELECT * 
                FROM servicetable 
                    WHERE MATCH(title,cat,brand,company) 
                        AGAINST ('".$searchquery."' IN BOOLEAN MODE)
                            ORDER BY title ASC";

    $result = $db->$query;
    $num_results = $result->num_rows;

    //show user what user searched.   
    echo $searchquery;

    echo "<p>Results found: ".$num_results."</p>";

   //counts results.    
   if ($num_results == 0)    
   {    
      echo "Sorry, but we can not find an entry to match your query<br><br>";    
   }    

  for ($i=0; $i <$num_results; $i++) {
     $row = $result->fetch_assoc();
     echo "<p><strong>".($i+1).". Outlet Name: ";
     echo stripslashes($row['title']);

     echo "</strong><br />Category: ";
     echo stripslashes($row['cat']);
     echo "<br />Opening Hours: ";
     echo stripslashes($row['ophours']);
     echo "<br />Brand: ";
     echo stripslashes($row['brand']);
          echo "</strong><br />Company: ";
     echo stripslashes($row['company']);
     echo "</p>";
  }

  $result->free();
  $db->close();
} else {
?>
        <h1>Search</h1> 
        <form name="form1" action="search.php" method="post"> 
            Enter Search:<br /> 
            <input type="text" name="query" id="query" placeholder="Search a service"/> 
                        <br/>
            <input type="submit" value="Search Now" name="completedsearch"  /> 
        </form> 

    <?php
}

?> 
4

1 回答 1

0

嗨,我发现了我的错误:

此行更正-->

$result = $db->query($query);
于 2015-02-06T08:58:43.850 回答