快速的问题,可能很简单,也可能不是。我不精通 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);
?>