[英]How retrieve specific data from database mysql
I have a search.php
in this I'm searching for three fields: 我有一个search.php
,我正在搜索三个字段:
But when I select a From no.
但是,当我选择“ From no.
, from select option and enter in input a Telephone no.
在选择选项中,然后输入输入Telephone no.
and press the search button it search for telephone no. 然后按搜索按钮搜索电话号码。 instead of form no. 而不是表格号 I want a search like when I select From no.
我希望像选择From no.
时一样进行搜索From no.
and enter a value of than it should search only for form no nothing else and like all below two option: 并输入一个比,它应该只搜索表单,别无其他,就像下面两个选项一样:
serach.php
<div class="tleft">
<h2 class="tdilouge">Search Reports</h2><center>
<table class="tbleft">
<form action="searchbyform.php" method="get">
<thead>
<tr>
<td>
<select name="formnumber" id="formnumber" >
<option>Form No.</option>
<option>Name</option>
<option>Telephone No.</option>
</select>
</td>
<td><input type="text" name="formnumber" id="formnumber" placeholder="Enter" /></td>
<td><input type="submit" value="Search" /></td>
</tr>
</thead>
</form>
</table></center>
</div>
And this is submit.php
I have a proper connection of database and column is table name: 这是submit.php
我有一个正确的数据库连接,列是表名:
submit.php
<?php
$formnumber = $_GET['formnumber'];
$sql = "SELECT * FROM colomn WHERE FormNo = $formnumber OR ConsumerName = $formnumber OR TelephoneNo = $formnumber";
$query = mysql_query( $sql );
if(mysql_num_rows($query) == 0)
{
echo "no result found";
}
echo "<table>";
echo "<thead></thead>";
while( $row = mysql_fetch_array( $query ) )
{
echo "<tr></tr>";
}
echo "</table>";
?>
You could just check which option the person has selected and depending on that selected option you could run the query that belong to that option. 您可以只检查人员选择了哪个选项,然后可以根据所选选项运行属于该选项的查询。 Give the options a value, like this: 给选项赋一个值,如下所示:
(You should change the select name because the textfield is already named formnumber
) (您应该更改选择名称,因为文本字段已经被命名为formnumber
)
<select name="form" id="form" >
<option value="form">Form No.</option>
<option value="name">Name</option>
<option value="telephone">Telephone No.</option>
</select>
So when you choose the option form no. 因此,当您选择选项表格编号时。 , $_GET['form']
would be "form" , $_GET['form']
为“表单”
So just use an IF to check the 3 options. 因此,只需使用IF检查3个选项即可。
EDIT: The query when the Form no. 编辑:当窗体号时查询。 has been chosen, will look like this: 已被选择,将如下所示:
"SELECT * FROM colomn WHERE FormNo = $formnumber" “选择*从列WHERE FormNo = $ formnumber”
And for the name and telephone no. 并提供姓名和电话号码。 You should just change the column name. 您应该只更改列名称。
if($_get['form']="form"){
$sql="SELECT * FROM colomn WHERE FormNo = $formnumber";
}
if($_get['form']="name"){
$sql="SELECT * FROM colomn WHERE ConsumerName = $formnumber";
}
if($_get['form']="telephone"){
$sql="SELECT * FROM colomn WHERE TelephoneNo = $formnumber";
}
Also dont use mysql. 也不要使用mysql。 Use mysqli or PDO instead. 改用mysqli或PDO。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.