【问题标题】:Search from mysql results in a table in PHP在 PHP 中从 mysql 结果中搜索一个表
【发布时间】: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">&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>" ;
}

   ?>

【问题讨论】:

    标签: php mysql sql


    【解决方案1】:

    试试这个

      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表格

    read this

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

    【讨论】:

    • :) ,你又来了 :) ! .
    • 又是我,哈哈,它可以正常工作并正确显示。我刚刚阅读了有关 Html 表的信息,我将尝试将其添加到我已经拥有的 css 文件中。
    • 很高兴它对你有用 :) !只要确保接受答案。
    • 您知道如何获得一个结果来填充表单中的字段吗?就像在该表的参考编号上创建一个链接,将那一行的数据移回表单?
    • 如果你愿意,可以通过 ajax 制作。
    猜你喜欢
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    相关资源
    最近更新 更多