-1

我为我的网页制作了一个搜索功能,但我的表格似乎重叠了。这是当我搜索出现在三行中的单词“server”时表格的样子

图片

如果您看到我的结果,标题会重复和重叠。

这是我的代码,我真的不知道我是否犯了错误。

<?php
include 'includes/connect.php';
$query = $_GET['query'];
$min_length = 3;
if (strlen($query) >= $min_length) {

    $query = htmlspecialchars($query);
    $query = mysql_real_escape_string($query);

    $raw_results = mysql_query("SELECT * FROM aggrement
                WHERE (`id` LIKE '%" . $query . "%') OR(`description` LIKE '%" . $query . "%') OR (`start_date` LIKE '%" . $query . "%') OR (`end_date` LIKE '%" . $query . "%') OR (`balance` LIKE '%" . $query . "%') OR (`tax_value` LIKE '%" . $query . "%') OR (`amount_paid` LIKE '%" . $query . "%') OR (`hosting_name` LIKE '%" . $query . "%') OR (`domain_name` LIKE '%" . $query . "%') OR (`first_name` LIKE '%" . $query . "%') OR (`last_name` LIKE '%" . $query . "%')") or die(mysql_error());

    if (mysql_num_rows($raw_results) > 0) {
        echo "<table>";
        // echo your header row here
        while ($results = mysql_fetch_array($raw_results)) {

            echo "<tr>
          <th>Id</th>
          <th><a href='viewaggrement.php?sort=description'>Description</th>
          <th><a href='viewaggrement.php?sort=start_date'>Start Date</th>
          <th><a href='viewaggrement.php?sort=end_date'>End Date</th>
          <th><a href='viewaggrement.php?sort=balance'>Balance</th>
          <th><a href='viewaggrement.php?sort=tax_value'>Tax </th>
          <th><a href='viewaggrement.php?sort=amount_paid'>Amount Paid</th>
         <th><a href='viewaggrement.php?sort=domain_name'>Domain Name</th>
         <th><a href='viewaggrement.php?sort=hosting_name'>Hosting Name</th>
        <th><a href='viewaggrement.php?sort=first_name'>First Name</th>
        <th><a href='viewaggrement.php?sort=last_name'>Last Name</th>
        <th>Edit</th>
        <th>Delete</th>
        </tr>";

            echo "<tr>";
            echo "<td>" . $results['id'] . "</td>";
            echo "<td>" . $results['description'] . "</td>";
            echo "<td>" . $results['start_date'] . "</td>";
            echo "<td>" . $results['end_date'] . "</td>";
            echo "<td>" . $results['balance'] . "</td>";
            echo "<td>" . $results['tax_value'] . "</td>";
            echo "<td>" . $results['amount_paid'] . "</td>";
            echo "<td>" . $results['hosting_name'] . "</td>";
            echo "<td>" . $results['domain_name'] . "</td>";
            echo "<td>" . $results['first_name'] . "</td>";
            echo "<td>" . $results['last_name'] . "</td>";
            echo '<td><b><a href="editaggrement.php?id=' . $results['id'] . '"><img src="images/icons/glyphicons_030_pencil.png" /></a></b></td>';
            echo '<td><b><a href="deleteaggrement.php?id=' . $results['id'] . '"><img src="images/icons/glyphicons_016_bin.png" /></a></b></td>';
            echo "</tr>";
        }
        echo "</table>";
    } else {
        echo "No results";
    }

} else {
    echo "Minimum length is " . $min_length;
}
?>
4

2 回答 2

3

更改以下内容:

while($results = mysql_fetch_array($raw_results)) {

     echo "<tr>
  <th>Id</th>
  <th><a href='viewaggrement.php?sort=description'>Description</th>
  <th><a href='viewaggrement.php?sort=start_date'>Start Date</th>
  <th><a href='viewaggrement.php?sort=end_date'>End Date</th>
  <th><a href='viewaggrement.php?sort=balance'>Balance</th>
  <th><a href='viewaggrement.php?sort=tax_value'>Tax </th>
  <th><a href='viewaggrement.php?sort=amount_paid'>Amount Paid</th>
 <th><a href='viewaggrement.php?sort=domain_name'>Domain Name</th>
 <th><a href='viewaggrement.php?sort=hosting_name'>Hosting Name</th>
<th><a href='viewaggrement.php?sort=first_name'>First Name</th>
<th><a href='viewaggrement.php?sort=last_name'>Last Name</th>
<th>Edit</th>
<th>Delete</th>
</tr>";

echo "<tr>
  <th>Id</th>
  <th><a href='viewaggrement.php?sort=description'>Description</th>
  <th><a href='viewaggrement.php?sort=start_date'>Start Date</th>
  <th><a href='viewaggrement.php?sort=end_date'>End Date</th>
  <th><a href='viewaggrement.php?sort=balance'>Balance</th>
  <th><a href='viewaggrement.php?sort=tax_value'>Tax </th>
  <th><a href='viewaggrement.php?sort=amount_paid'>Amount Paid</th>
 <th><a href='viewaggrement.php?sort=domain_name'>Domain Name</th>
 <th><a href='viewaggrement.php?sort=hosting_name'>Hosting Name</th>
<th><a href='viewaggrement.php?sort=first_name'>First Name</th>
<th><a href='viewaggrement.php?sort=last_name'>Last Name</th>
<th>Edit</th>
<th>Delete</th>
</tr>";
while($results = mysql_fetch_array($raw_results)) {
于 2013-04-16T20:39:20.080 回答
0
     echo "<tr>
  <th>Id</th>
  <th><a href='viewaggrement.php?sort=description'>Description</th>
  <th><a href='viewaggrement.php?sort=start_date'>Start Date</th>
  <th><a href='viewaggrement.php?sort=end_date'>End Date</th>
  <th><a href='viewaggrement.php?sort=balance'>Balance</th>
  <th><a href='viewaggrement.php?sort=tax_value'>Tax </th>
  <th><a href='viewaggrement.php?sort=amount_paid'>Amount Paid</th>
 <th><a href='viewaggrement.php?sort=domain_name'>Domain Name</th>
 <th><a href='viewaggrement.php?sort=hosting_name'>Hosting Name</th>
<th><a href='viewaggrement.php?sort=first_name'>First Name</th>
<th><a href='viewaggrement.php?sort=last_name'>Last Name</th>
<th>Edit</th>
<th>Delete</th>
</tr>";

将该块移动到您的 while 循环上方。

于 2013-04-16T20:38:30.687 回答