繁体   English   中英

从mysql搜索结果在PHP表中

[英]Search from mysql results in a table in PHP

如何将查询的搜索结果放入表中,然后选择一个条目以更新表单中的详细信息?

所以我有我的表格:姓名,地址,电话,邮政编码,电子邮件等。

我有一个搜索查询,搜索的邮政编码。

我有一个结果列表,然后我要选择一个结果(选择按钮或类似按钮),然后将其余信息重新填写到表单中。

形式看起来像这样

<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">&nbsp;</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>" ;
}

   ?>

尝试这个

  echo"<table><tr>" ;
  echo '<th>Reference</th><th>Physio</th><th>Postcode</th><th>Line1</th><th>Tel</th></tr>';
    while ($search_rs = mysql_fetch_array($search_query))
         {
         echo '<tr>';
         echo "<td>".$search_rs['Reference'] . "</td>";
         echo "<td>".$search_rs['Physio'] . "</td>";
         echo "<td>".$search_rs['Postcode'] . "</td>";
         echo "<td>".$search_rs['Line1'] . "</td>";
         echo "<td>".$search_rs['Tel'] . "</td>";
         echo '</tr>';
         }
  echo '</table>';

为了学习在php中建立html表格的目的

读这个

    echo "<td><a href="url">".$search_rs['Reference'] . "</a></td>";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM