创建不同的搜索框? [英] Create different seach box ?

查看:38
本文介绍了创建不同的搜索框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的名字Qasem,我来自阿富汗,

我在学校有一个学生数据库,因为我们有同名学生和父亲名字的学生,当我只搜索名字它显示我100名,然后搜索只有父亲名称它显示我50名,我怎么能创建3个txt框一个名字一个为父亲的名字和另一个为像学生ID和点击搜索这三个框一起工作和搜索。

我希望你知道我的问题并帮助我。

非常感谢你。



我的尝试:



在你管中找不到任何东西来告诉我我是怎么做的。

Hi my name Qasem, Im from Afghanistan,
I have a db for student in school and for a reason like we have student with the same name and fathers name, when i search only by the name it shows me 100 name, then search with just fathers name it shows me 50 name, how can i create 3 txt box one for name one for father name and another for like student id and when click to search these three box work together and search.
I hope you know my problem and help me.
thank you so much.

What I have tried:

in you tube finding nothing to show me how i do this.

推荐答案

简单:创建一个在WHERE中使用AND子句的SELECT语句声明:

Simple: create a SELECT statement which uses AND clauses in the WHERE statement:
SELECT ... WHERE studentName = 'John' AND fatherName = 'Mike'

这会导致DB仅返回两个条件的行是真的。你所要做的就是用文本框内容替换固定的字符串。



但请注意两件事:

1)自从StudentID将是唯一的(或者它不是ID值,并且您的系统中存在非常非常错误的东西)如果您通过AND在WHERE标准中包含它,您将只获得一行或者没有 - 其余的标准几乎无关紧要。

2)永远不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。谷歌将向您展示如何做到这一点(但根据您使用什么来访问数据库,它会略有不同,所以我不能举一个例子)。

This causes the DB to only return rows where both conditions are true. All you have to do is replace the fixed strings with the text box content.

But do note two things:
1) Since the StudentID will be unique (or it isn't an ID value, and you have something very, very wrong in your system) if you include that in your WHERE criteria via an AND you will only get one row or none - the rest of the criteria are pretty much irrelevant.
2) Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. Google will show you how to do that (but it'll be slightly different depending on exactly what you are using to access the DB, so I can't give you an example).


这篇关于创建不同的搜索框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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