dongyue3795
2014-03-04 00:28
浏览 22
已采纳

php MySql查询`LIKE'$ word'`返回NULL

In the code below the

var_dump($row);

shows NULL

$query = "SELECT * FROM maintable WHERE Category LIKE '$word'
                                                        OR Title LIKE '$word'
                                                        OR Title2 LIKE '$word'
                                                        OR Description LIKE '$word'
                                                        OR Description2 LIKE '$word'
                                                        OR Preimushestva LIKE '$word'
                                                        OR Preimspisok LIKE '$word';";

            $result = mysqli_query($link, $query)
            or die("Error: ".mysqli_error($link));

            $row = mysqli_fetch_array($result, MYSQLI_ASSOC);

            var_dump($row);

and $word = 'dolor' and I have word dolor in my table, in Description tab help me find mistake please

图片转代码服务由CSDN问答提供 功能建议

在下面的代码中

  var_dump($ row)  ; 
   
 
 

显示 NULL

  $ query =“SELECT * FROM maintable WHERE 类别LIKE'$ word'
 OR Title LIKE'$ word'
 OR Title2 LIKE'$ word'
 OR描述LIKE'$ word'
 OR Description2 LIKE'$ word'
 OR Preimushestva LIKE'$ word  '
或者Preimspisok LIKE'$ word';“; 
 
 $ result = mysqli_query($ link,$ query)
或者死(”错误:“。mysqli_error($ link)); 
 
 $  row = mysqli_fetch_array($ result,MYSQLI_ASSOC); 
 
 var_dump($ row); 
   
 
 

$ word ='dolor' and我h 我的表中的ave word dolor,在描述选项卡中帮我找错了

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanjiuhong5843 2014-03-04 00:30
    已采纳

    You're missing your pattern matching characters. Without them LIKE is essentially the same as =.

    Here's an example:

    $query = "SELECT * FROM maintable WHERE Category LIKE '%$word%'
                                                        OR Title LIKE '%$word%'
                                                        OR Title2 LIKE '%$word%'
                                                        OR Description LIKE '%$word%'
                                                        OR Description2 LIKE '%$word%'
                                                        OR Preimushestva LIKE '%$word%'
                                                        OR Preimspisok LIKE '%$word%';";
    
    已采纳该答案
    打赏 评论
  • duanfu5239 2014-03-04 00:30

    Look at this link : http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

    $query = "SELECT * FROM maintable
                  WHERE Category LIKE '%".$word."%'
                  OR Title LIKE '%".$word."%'
                  OR Title2 LIKE '%".$word."%'
                  OR Description LIKE '%".$word."%'
                  OR Description2 LIKE '%".$word."%'
                  OR Preimushestva LIKE '%".$word."%'
                  OR Preimspisok LIKE '%".$word."%';";
    
    打赏 评论
  • duanhuren5581 2014-03-04 00:31

    My best guess would be that you need to search for '%dolor%'. The expression like without any wild card characters searches for an exact match.

    However, it would help if you printed out the query after the variable substitution. You can edit your question with this information if the wildcard form doesn't fix your problem.

    打赏 评论

相关推荐 更多相似问题