0

我有一个页面,用户在其中搜索 pdf,结果显示在该页面中,但显示在特定的 div 中。显示了表格,但页面的整个设计被破坏了......有人能指出我是什么吗在这里做错了吗?

    <div id="content">
   <div class="post">
        <div class="entry">
        <form name="search" action="" method="post">
        <input type="text" class="search" name="searchbox" id="searchbox" />
        <input type="submit" name="search" id="search" value="Search" />
        </form>

        </div>
    </div>

    <div class="post">
         <div class="entry">
         <?php
              if(isset($_REQUEST['search'])){
                  $searchterm = $_REQUEST['searchbox'];
                  $sql = "select name,size from ebooks where name like '%$searchterm%'";
                  $result=mysql_query($sql);
                  if(!($result)){
                     die("Query to show fields from table failed");
                  }
                  $fields_num = mysql_num_fields($result);
                  echo "<table border='1'><tr>";
                  // printing table headers
                  for($i=0; $i<$fields_num; $i++){
                      $field = mysql_fetch_field($result);
                      echo "<td>{$field->name}</td>";
                  }
                  echo "</tr>\n";
                  // printing table rows
                  while($row = mysql_fetch_row($result)){
                  echo "<tr>";
                  // $row is array... foreach( .. ) puts every element
                  // of $row to $cell variable
                  foreach($row as $cell)
                  echo "<td>$cell</td>";
                  echo "</tr>\n";
                  }
                  mysql_free_result($result);

              }
         ?>
         </div>

    </div>

4

1 回答 1

1

你的桌子不关门</table>吗?

这里是正确的代码:

<?php
if (isset($_REQUEST['search'])) {

    $searchterm = $_REQUEST['searchbox'];
    $sql = "SELECT `name`, `size` FROM `ebooks` WHERE `name` LIKE '%$searchterm%'";
    $result = mysql_query($sql);

    if (!($result)){
        die("Query to show fields from table failed");
    }

    $fields_num = mysql_num_fields($result);
    echo "<table border=\"1\">\n<tr>";

    for ($i=0; $i<$fields_num; $i++) {
        $field = mysql_fetch_field($result);
        echo "<td>{$field->name}</td>";
    }

    echo "</tr>\n";

    while ($row = mysql_fetch_row($result)) {
        echo "<tr>";
        foreach($row as $cell) {
            echo "<td>$cell</td>";
        }
        echo "</tr>\n";
    }

    echo "</table>\n";

    mysql_free_result($result);
}
?>
于 2013-04-02T12:19:17.377 回答