- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从网上得到这个语法并修改了一些部分。我想在表中定位/搜索记录。此语法最终显示为“未找到搜索查询”我找不到此语法中的问题。你能帮我找点错误吗?这是语法。
<?php // Get the search variable from URL
if(!isset($_GET['q']))
die('Search Query not found');
$var = $_GET['q'];
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == ""){
echo "<p>Please enter a search…</p>";
exit;
}
// check for a search parameter
if (!isset($var)){
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","user1","test123");
//specify database ** EDIT REQUIRED HERE **
mysql_select_db("inventory") or die("Unable to select database");
// Build SQL Query
$query = ("SELECT * FROM client WHERE account_name LIKE \"%$trimmed%\" or maintenance_type like \"%$trimmed%\" or ma_status like \"%$trimmed%\" ma_contract_start like \"%$trimmed%\" ma_contract_end like \"%$trimmed%\" ma_reference_no like \"%$trimmed%\" ORDER BY account_name DESC");
// EDIT HERE and specify your table and field names for the SQL query
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// If we have no results, offer a google search as an alternative — this is optional
if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: $trimmed returned zero results</p>";
// google
echo "<p><a href=\"http://www.google.com/search?q="
. $trimmed . "\" target=\"_blank\" title=\"Look up
" . $trimmed . " on Google\">Click here</a> to try the
search on google</p>";
}
// next determine if s has been passed to script, if not use ZERO (0) to Limit the output
if (empty($s)) {
$s=0;
}
// get results
$query = " limit $s,$limit";
$result = mysql_query($query) or die("Couldn’t execute query");
// display what the person searched for
echo "<p>You searched for: $var </p>";
// begin to show results set
echo "Results: <br/>";
$count = 1 + $s ;
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$name = $row['account_name'];
$mtype = $row['maintenance_type'];
$status = $row['ma_status'];
$start = $row['ma_contract_start'];
$end = $row['ma_contract_end'];
$reference = $row['reference_no'];
echo "$count.> $name $mtype $status $start $end $reference <br/>" ;
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) {
// bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a> ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";
?>
最佳答案
您曾提到您遇到此错误“未找到搜索查询”。您编写的代码清楚地告诉 url 中未设置参数“q”。
if(!isset($_GET['q']))
die('Search Query not found');
如果这必须工作,你的 url 应该是
www.example.com?q=some_value
关于php - 如何为自己的网站制作搜索引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10528312/
任何人都可以帮我列出一个很好的 php 站点搜索引擎列表。我正在考虑实现谷歌站点搜索,但我宁愿不为此付费,而且我宁愿尽可能多地控制它。 最佳答案 通读Roll your own Search Engi
我正在使用 Laravel 为移动应用程序构建 REST api。现在我需要一个搜索引擎。 首先,我从未使用过任何搜索引擎。所以我正在寻找一个易于使用但仍然擅长全文搜索和过滤“where”的工具 我要
我正在建立一个公司网站。我们正在寻找任何基于 ASP.NET 的开源或付费搜索引擎。应该可以 搜索网站中所有页面的网页内容。 所有办公文件。等等 如果我们有一些基于用户类型和风格的搜索结果过滤。 请让
目前我正在尝试为我的网站创建一个搜索功能,允许用户使用他们的全名(名字或姓氏)或他们的用户名搜索其他用户。现在我已经创建了一个临时搜索,它使用 mysql 的 LIKE 功能和 %name% 来允许通
我正在尝试制作一个搜索引擎,但我遇到了这个错误 Notice: Undefined variable: construct in C:\xampp\htdocs\test\search.php on
我有这个“搜索”选项,它在其中查找表格所请求变量的标题和类别。 //This could be Reference or Product Name $name = mysqli_real_escape
你好 php 的另一个问题,我不确定为什么它不起作用,但这是代码: $keyword){ $where .="`keywords` LIKE '%$keyword%'";
我已经在空闲时间学习 PHP 几个星期了,这是我不得不寻求帮助的第一个问题。我在整个 Internet 上进行了搜索,但在使用具有两个输入字段的 PHP mysql 搜索引擎时,没有发现任何我能完全理
我正在尝试在关键术语表和页面之间进行搜索查询。 考虑下表。 页数 page_id page_name1 cats2 dogs3 humans 关键词 key
我正在尝试使用html ajax和jsp进行与google搜索相同的搜索引擎 1.当我在文本框中点击一个字符时,每次点击都会调用ajax 2.ajax 将其重定向到 jsp,其中我有一个简单的查询,该
我已经阅读了一些关于内置 python 附带的 re 模块的文档,但我似乎无法理解它。事实上,我不确定这就是我要找的东西,所以让我解释一下: 我有一本大字典。我想要的是能够输入搜索条件,例如 hell
我有一个包含多个对象的网络应用程序,其中有多个我想要搜索的String。我想按最佳“匹配”对“匹配”进行排序。示例:搜索“stackoverflow is Great”。 “Stackoverflow
我有一个新创建的 Web 应用程序托管在 AppEngine 中(仅 HTML)问题是,我怎样才能让这个页面出现在谷歌搜索引擎上?这类似于常规方法(robot.txt 等)吗? 谢谢! 最佳答案 只需
我想要一个只搜索我自己站点的搜索引擎。我目前有一些 JavaScript,但它只搜索特定页面上的单词。如果可能的话,我需要它来搜索我网站内的链接。 我无法使用 Google 搜索引擎,因为我的站点位于
目前,我有一个汽车品牌列表(本田,丰田,宝马,梅赛德斯·奔驰等)的表格(car_brands),并且我有一个标题,用户可以输入,例如mercedes benz e 230,所以我想输入用户可以通过搜索
我将在我的应用程序中使用 ElasticSearch 作为搜索存储库。我有一些关于组织方面的最佳实践的问题当对象彼此具有关联/关系时,搜索索引中的对象。 据我所知,搜索索引是一个平面结构,不符合以下概
基本要求: 应该能够索引 MediaWiki、Confluence、Sharepoint、GitHub:Enterprise、Askbot 等内容 应该相当聪明地去除重复结果(Confluence 搜
所以,我才刚刚开始阅读这方面的内容,我以前从未在 PHP 中实现过搜索。我想知道几个问题: 听起来,Sphinx 需要一个“守护进程”,一个运行在后台,操作? 假设我建立了一个 mySQL 的索引表,
我有一个包含 20 个文本文件的文件夹。我希望索引这个文件夹并在这些文件中搜索任何关键字。 我如何在 C# 中执行此操作? 最佳答案 这是对 lucene.Net 的一个很好的介绍: Introduc
我正在寻找可用于在我的网站上搜索内容的任何 javascript 库,我遇到了一些安静的但大多数它们需要使用数据库来存储索引以优化搜索查询,但我只需要一个内置javascript的数据库免费搜索引擎。
我是一名优秀的程序员,十分优秀!