求助:SQL语法错误'LIMIT 0,10'

在试图访问我的网站时,我遇到了这个错误:“您的sql语法出现了错误;请检查与MySQL服务器版本相对应的手册,以便在第1行使用‘限制0,10’的正确语法。”

我的第一行是:<?php require_once('Connections/blog.php'); ?>

但似乎这个错误是从这里来的:

$maxRows_getDisplay = 10;
$pageNum_getDisplay = 0;
if (isset($_GET['pageNum_getDisplay'])) {
  $pageNum_getDisplay = $_GET['pageNum_getDisplay'];
}
$startRow_getDisplay = $pageNum_getDisplay * $maxRows_getDisplay;

mysql_select_db($database_blog, $blog);
$query_getDisplay = "SELECT news.title, news.pre,  
 DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted 
 FROM news ORDER BY news.updated DESC LIMIT 2";
$query_limit_getDisplay = sprintf("%s LIMIT %d, %d", 
 $query_getDisplay, $startRow_getDisplay, $maxRows_getDisplay);
$getDisplay = mysql_query($query_limit_getDisplay, $blog) or die(mysql_error());
$row_getDisplay = mysql_fetch_assoc($getDisplay);

如果你有什么想法,请告诉我,因为我完全懵了。

You have created an SQL statement with two LIMIT clauses, which is not allowed.

This example shows how difficult it is to debug SQL by staring at the code you use to build up a SQL string.

It's much easier if you can output the final SQL string to debug it.

$query_getDisplay = "SELECT news.title, news.pre,  
 DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted 
 FROM news ORDER BY news.updated DESC LIMIT 2";
$query_limit_getDisplay = sprintf("%s LIMIT %d, %d", 
 $query_getDisplay, $startRow_getDisplay, $maxRows_getDisplay);
error_log("What's wrong with this SQL?  " . $query_limit_getDisplay);
$getDisplay = mysql_query($query_limit_getDisplay, $blog) or die(mysql_error());

You'll see in your error log:

What's wrong with this SQL?  SELECT news.title, news.pre,  
DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted 
FROM news ORDER BY news.updated DESC LIMIT 2 LIMIT %d, %d

And that makes it much easier to spot invalid SQL syntax (assuming you can recognize valid vs. invalid SQL syntax).