如果我输入 2 个或更多字母,我正在使用的搜索代码适用于搜索,但是当我用一个字母查询它时,它会给我所有的数据列表,我有一个 where 状态,比如“找到”子句,但它仍然如果我放一个字母,会给我其他结果。如果我正确输入两个或更多字母,则搜索部分有效,但如果我输入一个字母,它会给我不同的查询结果。
这是我的 SQL 查询
> $searchtext = ''; if(isset($_GET['q'])) $searchtext =
> mysql_real_escape_string($_GET['q']); if($searchtext) {
> $per_page =16;
> $pages_query = mysql_query("SELECT COUNT('PersonID') FROM persons where firstname like '$searchtext' or
> lastname like '$searchtext' and status like 'found' ");
> $pages = ceil(mysql_result($pages_query,0) / $per_page);
>
> $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
> $start = ($page - 1) * $per_page;
>
>
> // And set the first page $first_page = "1";
>
> $num = mysql_num_rows($pages_query);
> $last_page = ($num / $per_page);
> $next_page = $page + 1;
> $last_page=$pages;
>
>
>
> $query=mysql_query("select * from persons where status like 'found' and firstname like '%$searchtext%' or lastname like
> '%$searchtext%' order by date desc LIMIT $start,$per_page ");
>
> $numrows = mysql_num_rows($query);
>
>
> }
>
> else {
>
> $per_page =16;
> $pages_query = mysql_query("SELECT COUNT('PersonID') FROM persons where status like 'found' ");
> $pages = ceil(mysql_result($pages_query,0) / $per_page);
>
> $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
> $start = ($page - 1) * $per_page;
> $last_page=$pages;
>
> // And set the first page $first_page = "1";
>
>
> $query=mysql_query("select * from persons where status like 'found' order by date desc LIMIT $start,$per_page ");
> $count=mysql_query("select * from persons where status like 'found'");
> $numrows = mysql_num_rows($count);
>
> }
此屏幕截图是默认视图。对此的查询是$query=mysql_query("select * from persons where status like 'found' order by date desc LIMIT $start,$per_page ");
此屏幕截图是我在默认视图中搜索找到并收到此结果时的搜索视图,dan
这是我用于输出的查询。` $query=mysql_query("select * from people where status like 'found' and firstname like '%$searchtext%' or lastname like '%$searchtext%' order by date desc LIMIT $start,$per_page ");
$numrows = mysql_num_rows($query);`
最后的图片显示我搜索了字母a
。给我的结果来自各个领域。另外,我有一个冲突,它还调用了丢失的列表,我只想将它限制为仅找到的,这也是查询丢失的问题,它也在整个找到的字段中找到。
我在这里使用的 SQL 命令是图 2 中的那个