dtsc14683 2014-06-15 13:01
浏览 40
已采纳

我的术语被搜索但是我的OR声明没有收到任何结果

session_start();

$_SESSION['word'] = $_POST['searchbar'];

$search = $_SESSION['word'];

if ($search == "") { //stopping any blank fields

echo "<p align=center><b>Please Enter Something To Search For In The Search Box.</b></p>";

}
else
{

$result = mysql_query("SELECT * FROM clothes WHERE (`title` LIKE '%".$search."%') || (`description` LIKE '%".$search."%')") or die(mysql_error()); //trying to do a statement that asks for a search to be done on TITLE and DESCRIPTION for what ever term someone has searched for so I can show them the results

echo "<p align=center>You Searched For $search</p>"; //showing the term that is being searched

if($result[0] == 0) //checking to see if the results come up as NONE then the following message to be shown
{
echo "<p align=center><b><font size=3>No Results Were Found.</font></b></p>";
}
else
{

//if there are some results from the term then the following tables are shown

echo "results shown here";

}
}

my issue I am having is I am not receiving any results with my OR statement.

The search term shows, the search works without the OR statement but as soon as I try to search the TITLE and DESCRIPTION columns for results it does not like it.

Any help?

  • 写回答

1条回答 默认 最新

  • douchen9855 2014-06-15 15:26
    关注
    session_start();
    
    $_SESSION['word'] = $_POST['searchbar'];
    
    $search = $_SESSION['word'];
    
    if ($search == "") {
    
    echo "<p align=center><b>Please Enter Something To Search For In The Search Box.</b></p>";
    
    }
    else
    {
    
     $searchTerms = explode(' ', $search);
     $searchTermBits = array();
     foreach ($searchTerms as $term) {
     $term = trim($term);
     if (!empty($term)) {
        $searchTermBits[] = "description OR title LIKE '%$term%'";
     }
     }
    
    
      $result = mysql_query("SELECT * FROM clothes WHERE ".implode(' OR ', $searchTermBits)."") or die(mysql_error());
    
    
      echo "<p align=center>You Searched For $search</p>";
    
    
       $journey = mysql_num_rows($result);
    
    if ($journey == 0) {
    
    echo "<p align=center><b>There Were No Results. Please Try Again</b></p>";
    
    }
    
    else
    
    {
    
    while($resultr=mysql_fetch_assoc($result))
    
    echo "result here";
    
      }
    
    }
    

    changed it quite a bit, it still reads off two areas but doesn't search for a precise term as it did before instead someone can search for "extra large mens tshirt" and mens tshirts will come up as long as that is stated in the TITLE or in the description "terms of Men or Tshirt or Large or Extra" etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记