1

当我运行以下代码时,我收到此错误:

致命错误:第 105 行 /Users/allan/Sites/4is_site/casestudyall.php 中的 SQL(这是下面代码的最后一行。

我的查询有问题吗?

<?php
if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} 
else {
   $pageno = 1;
}   

$query = "SELECT count(*) FROM studies ORDER BY (date) desc";
$result = mysql_query($query, $connection) or trigger_error("SQL", E_USER_ERROR);



$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 4;
$lastpage      = ceil($numrows/$rows_per_page);

$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
}
if ($pageno < 1) {
   $pageno = 1;
}
?>

<div class='column3'><p class='bodygrey'>

<?php

$totalpages = ceil($numrows / $rows_per_page);

if($totalpages >= 1){ $pagelinkcount = 1;} else { $pagelinkcount = 0; }

if($totalpages > 1){ $pagelinkcount = 1;  echo 'Page ';}

while($pagelinkcount <= $totalpages && $totalpages > 1) {




     echo "<a href=\"{$_SERVER['PHP_SELF']}?pageno={$pagelinkcount}\">{$pagelinkcount}</a> ";

     $pagelinkcount++;

}
?>
</p></div></div></div>
<?php


$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM studies".
         "ORDER BY date DESC $limit";


$result = mysql_query($query, $connection) or trigger_error("SQL", E_USER_ERROR);
4

1 回答 1

8

问题可能与以下代码有关:

$query = "SELECT * FROM studies".
         "ORDER BY date DESC $limit";

这将产生以下查询:

SELECT * FROM studiesORDER BY date DESC $limit

注意“studies”和“ORDER”之间缺少空格。

于 2009-07-02T02:34:31.830 回答