如何修复此错误?
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '-20, 20' 附近使用正确的语法
我网站中的相同脚本工作正常,但我上传到另一台服务器是 Windows 服务器并收到此错误。
<?php
//connect to database
mysql_connect('xyz.ipowermysql.com','itomi','password.');
mysql_select_db('itomi');
$max_results = 20;
$from = (($page * $max_results) - $max_results);
if(empty($_POST)) {
$query = "SELECT * FROM `itomi` WHERE `ntitle` LIKE '".$letter."%' ORDER BY `ntitle` ASC LIMIT $from, $max_results";
}
$result = mysql_query("SET NAMES utf8"); //the main trick
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
echo "<table class='hovertable' border='1' cellpadding='0' cellspacing='0'>";
echo "<tr><th>Keyword</th><th>Title</th><th>Detail</th></tr>";
if ($rows > 0) {
while($row = mysql_fetch_array($result)) {
echo "<tr><td>";
echo '<a href="detail.php?id=' . $row['id'] . '" class="style1">' .$row['ntitle'].' </a>';
echo "</td><td>";
echo $row['ndetails'];
echo "</td><td>";
echo $row['counter'];
echo "</td></tr>";
}
} else {
echo "<tr><td colspan=\"5\">No results found!</td></tr>";
}
echo "</table>";
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as ntitle FROM itomi ORDER BY ntitle ASC"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<p class=\"style1\">Pages: ";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['php_SELF']."?page=$prev&letter=$letter\" class=\"style1\">Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo " ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['php_SELF']."?page=$next&letter=$letter\" class=\"style1\">Next</a>";
}
echo "</p>";
mysql_close();