mysql_fetch_assoc之后HTML表大小太大

时间:2017-10-18 17:16:30

标签: php html mysql sql html-table

将数据库值放入HTML表格后,表格变得很大。任何CSS代码都没有帮助。我要改变数据库值类型中的某些内容吗?还是其他任何建议?

以下是代码:

<?php

  $connector = mysql_connect('localhost','root','')
      or die("Unable to connect");
    echo "Connections are made successfully::";
  $selected = mysql_select_db("user_registration", $connector)
    or die("Unable to connect");

  //execute the SQL query and return records
  $result = mysql_query("SELECT * FROM login ORDER BY 1 DESC ");


  ?>

  <table class="table1" border="2"  >
  <thead>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Surename</th>
      <th>Email</th>
      <th>Gender</th>
      <th>Username</th>
      <th>Password</th>
    </tr>
  </thead>
  <tbody>
    <?php
      while( $row = mysql_fetch_assoc( $result ) ){
        echo
        "<tr >
          <td >{$row['id']}</td>
          <td>{$row['name']}</td>
          <td>{$row['surename']}</td>
          <td>{$row['email']}</td>
          <td>{$row['gender']}</td>
          <td>{$row['username']}</td>
          <td>{$row['password']}</td> 
        </tr>\n";
      }
    ?>
  </tbody>
</table>
 <?php mysql_close($connector); ?>

1 个答案:

答案 0 :(得分:1)

您需要选择记录的子集,否则页面将以与数据库表一样快的速度增长...使用LIMIT语句一次返回页面...

SELECT id, name, etc
FROM MyTable
ORDER BY id
LIMIT (0, 20)

下一页是

SELECT id, name, etc
FROM MyTable
ORDER BY id
LIMIT (20, 20)

等等。