如何创建搜索框以查找我网站的内部内容? [英] How to create search box to find the internal contents of my website?

查看:105
本文介绍了如何创建搜索框以查找我网站的内部内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有



我想在我的网站中包含搜索框,可以在本地找到我网站的内容。请指导我如何在我的网站上添加搜索功能。









问候



Amy

Dear All

I want to include the search box in my website which will find the contents of my website locally. Please guide me how to add search functionality in my website.




Regards

Amy

推荐答案

在数据库中搜索只是一个带<$ c的简单SQL查询$ c> LIKE 子句查找相对记录。虽然它只需要一个简单的输入控件(输入元素),以及一个您将处理用户输入的页面,然后查询然后根据查询和数据库记录生成结果。



例如,我的这篇文章,如何使用ASP.NET在数据库中搜索相关查询 [ ^ ],涵盖您正在寻找的主题。它只使用一个输入元素,并在提交时在数据库中查找可能有查询的记录。



样本是,

Search in database is just a simple SQL query with LIKE clause to find a relative record. Although it just needs a simple input control (input element), and a page where you will handle the user input, the query and then generate results as per the query and database records.

For example, this article of mine, How to search for related query inside the Database using ASP.NET[^], covers the topic that you are finding. It simply uses a single input element, and upon submission it looks for records in the database that might have the query in it.

A sample would be,
SELECT * FROM table_name WHERE column_name LIKE %parameter%





始终使用参数来防止SQL注入,上面的代码会查找匹配的记录(我使用过%%搜索任何单词,从关键字开始,结尾或包含关键字)关键字,参数化关键字。您可以使用ASP.NET Web Helpers的数据库对象以多种方式执行它,也可以使用 SqlClient 进行连接到数据库。



Always use parameters to prevent SQL Injections, above code would look for records that match (I have used %% that would search for any word, starting with, ending with or containing the keyword) your keyword, parameterized keyword. You can execute it in many ways, using ASP.NET Web Helpers' Database object or you can use SqlClient to connect to database.


这篇关于如何创建搜索框以查找我网站的内部内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆