【发布时间】:2014-02-13 13:14:40
【问题描述】:
如何将查询中的搜索结果放入表中,然后选择一个条目以更新表单中的详细信息?
所以我有我的表格:姓名、地址、电话、邮政编码、电子邮件等。
我有一个搜索邮政编码的搜索查询。
我有一个结果列表,然后我想选择一个(选择按钮或类似的东西)并将其余信息填回我的表单。
表格是这样的
<td><form action="searchresults.php" method="post" name="form1" id="form1">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Find a Active Physio</strong></td>
</tr>
<tr>
<td width="100">Physio Reference</td>
<td width="301"><input name="PhysioReference" type="text" id="PhysioReference" /></td>
</tr>
<tr>
<td>Name of Physio</td>
<td><input name="Physio" type="text" id="Physio" /></td>
</tr>
<tr>
<td>Contact Number</td>
<td><input name="Number" type="text" id="Number" /></td>
</tr>
<tr>
<td>Address</td>
<td><input name="PhysiosAddress" type="text" id="PhysiosAddress" /></td>
</tr>
<tr>
<td>Postcode</td>
<td><input name="postcode" value="" type="text" id="postcode" />
<input type="submit" name="submit" value="Search" /></td>
</tr>
<tr>
<td>Physios Email</td>
<td><input name="PhysiosEmail" type="text" id="PhysiosEmail" /></td>
</tr>
<tr>
<td colspan="3" align="center"> </td>
</tr>
</table>
</form></td>
这样的搜索结果(需要把它们放到表格中)
<?php
require_once('auth.php');
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="Physio"; // Table name
// Connect to server and select database.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
if(!isset($_POST['postcode'])) {
header ("location:index.php");
}
echo "<p> Results </p>" ;
$search_sql = "SELECT * FROM `Physio` WHERE Postcode like '%" . $_POST['postcode'] . "%'";
$search_query = mysql_query($search_sql);
while ($search_rs = mysql_fetch_array($search_query))
{
echo $search_rs['Reference'] . '<br>';
echo $search_rs['Physio'] . '<br>';
echo $search_rs['Postcode'] . '<br>';
echo $search_rs['Line1'] . '<br>';
echo $search_rs['Tel'] . '<br>';
}
if (!empty($search_rs))
{
echo "<p> Results Found </p>" ;
}
else
{
echo "<p> No Results Found </p>" ;
}
?>
【问题讨论】: