如何从数据库中搜索部分单词

时间:2016-12-09 19:01:33

标签: php sql database search

我正在创建一个搜索框,它只能通过部分写入值来工作,但我不知道怎么做?
这是代码:

  $sql = "SELECT id, name, someElse FROM My.basic_info WHERE id = '.$searched.' LIKE '%" .$searched."%' ";


    $result = mysql_query($sql) or die ("Query to POST data from try failed: ".mysql_error());


    if ($rows=mysql_fetch_assoc($result)) {




           echo $rows['id'];
           echo "<br>";

           echo $rows['name'];
           echo "<br>";

           echo $rows['someElse'];
           echo "<br>";


      } else {
        echo "What you've searched for cannot be found or isn't the correct checkbox";
        echo "<br>";
      }

为什么不起作用?在此先感谢!!

1 个答案:

答案 0 :(得分:0)

首先,尝试删除sql的字符串中的变量:

$sql = "SELECT id, name, someElse FROM My.basic_info WHERE id LIKE '%" .$searched."%' ";