Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP在SQL数据库中搜索部分匹配_Php_Mysql_Sql_Search - Fatal编程技术网

使用PHP在SQL数据库中搜索部分匹配

使用PHP在SQL数据库中搜索部分匹配,php,mysql,sql,search,Php,Mysql,Sql,Search,我有一个搜索SQL数据库的php文件。它从文本框中获取一个字符串,并尝试将其与数据库的各种属性相匹配。以下是执行搜索操作的代码: if ($filter['meta_info']) { $search_string = $filter['meta_info']; unset($filter['meta_info']); $m_intSortField = null; $m_strWhere .= (($m_strWhere) ? " AND " : "")

我有一个搜索SQL数据库的php文件。它从文本框中获取一个字符串,并尝试将其与数据库的各种属性相匹配。以下是执行搜索操作的代码:

    if ($filter['meta_info']) {
    $search_string = $filter['meta_info'];
    unset($filter['meta_info']);
    $m_intSortField = null;
    $m_strWhere .= (($m_strWhere) ? " AND " : "")."(MATCH     (`courses`.`assigned_id`,`courses`.`title`,`courses`.`author`,`courses`.`keywords`,`courses`.`  abstract`,`courses`.`objective`,`courses`.`summary`,`courses`.`copyright`,`courses`.`notes`) AGAINST ('".mysql_escape_string($search_string)."' IN BOOLEAN MODE))";
}

我的问题是,我希望它返回与指定ID部分匹配的课程,而不仅仅是完全匹配的课程。有人知道我是如何做到这一点的吗?

关闭mysql选项的严格模式,或者像这样使用

从课程中选择id、名称,其中名称如“English%”

返回

|  id | Name
|  2  | English Literature
|  8  | English Language

我自己做了更多的研究,找出了可以使用的各种操作符,解决了我的大部分问题。如果我想搜索GEN,它是许多课程中指定id的一部分,我会搜索GEN*。我现在唯一的问题是数字,一些客户机分配的ID只是数字。我找不到这个。