PHP / MySQL - 页面/排序缓慢加载

时间:2013-03-25 17:25:40

标签: php html mysql

快速提问,可能很简单,也许不是。我不熟悉PHP,HTML或MySQL,但我正在考虑它。以下是我正在使用的示例页面:http://www.djdarby.com/sorter.php。我正在展示一张19600年的桌子,其中包含两个领域,艺术家和歌曲。问题是它加载速度非常慢,我不知道在哪里指向手指。也许我的查询太简单了,或者我一次加载太多。这是代码,因为PHP在页面源上变得不可见。有没有更快的方法输出这些数据?

编辑:我忘了提及我正在使用javascript制作表格,TinyTable是准确的。

编辑NUMERO DOS:我制作了sorter2.php,它似乎加载得更快,这是一个javascript问题吗?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
        $con = mysql_connect("xx.xx.xx.xx", "xxxx", "xxx");
       // if (!$con) {
       //         die("Database connection failed: " . mysql_error());
       // } else {
       //         echo "\r\nConnected to the database.";
       // }
        $db = mysql_select_db("djdarby", $con);
       // if (!$db) {
       //         die("Database selection failed: " . mysql_error());
       // } else {
       //         echo "\r\nSelected to the database.";
       // }
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TinyTable</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="sortable">
                <thead>
                        <tr>
                                <th><h3>Artist</h3></th>
                                <th><h3>Song</h3></th>
                        </tr>
                </thead>
                <tbody>
                        <?php
                          $result = mysql_query("SELECT * from SONGLIST", $con);
                          //if (!$result) {
                          //  die("Query failed: " . mysql_error());
                          //} else {
                          //  echo "\r\nSelected the table SONGLIST in database djdarby.<br /><br />";
                          //}

                          while ($row = mysql_fetch_array($result)) {
                            echo "<tr><td>" . $row['ARTIST'] . "</td>" . "<td>" . $row['SONG'] . "</td></tr>";
                          }
                        ?>
                </tbody>
  </table>
        <div id="controls">
                <div id="perpage">
                        <select onchange="sorter.size(this.value)">
                        <option value="5">5</option>
                                <option value="10" selected="selected">10</option>
                                <option value="20">20</option>
                                <option value="50">50</option>
                                <option value="100">100</option>
                                <option value="250">250</option>
                        </select>
                        <span>Entries Per Page</span>
                </div>
                <div id="navigation">
                        <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                        <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                        <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                        <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div id="text">Displaying Page <span id="currentpage"></span> of <span id="pagelimit"></span></div>
        </div>
        <script type="text/javascript" src="script.js"></script>
        <script type="text/javascript">
  var sorter = new TINY.table.sorter("sorter");
        sorter.head = "head";
        sorter.asc = "asc";
        sorter.desc = "desc";
        sorter.even = "evenrow";
        sorter.odd = "oddrow";
        sorter.evensel = "evenselected";
        sorter.oddsel = "oddselected";
        sorter.paginate = true;
        sorter.currentid = "currentpage";
        sorter.limitid = "pagelimit";
        sorter.init("table",1);
  </script>
</body>
</html>
<?php
  mysql_close($con);
?>

1 个答案:

答案 0 :(得分:0)

在查询字符串中追加“LIMIT $ start,$ stop”,尽量不要在一个页面中使用太多记录