当我运行以下代码时,我收到此错误:
致命错误:第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);
答案 0 :(得分:8)
问题可能来自以下代码:
$query = "SELECT * FROM studies".
"ORDER BY date DESC $limit";
这将产生以下查询:
SELECT * FROM studiesORDER BY date DESC $limit
注意“研究”和“订单”之间缺少空格。