【发布时间】:2014-07-09 21:22:54
【问题描述】:
1064:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 4 行的 '' 附近使用的正确语法
SELECT a.* FROMws_itemsa WHERE 1 ANDenabled=1 ANDvisible=1 ORDER BYcreatedDESC 限制 0,
我搜索了该网站,但没有一个符合我的查询。我不知道如何使用mysql,但我确实需要解决这个问题...... 也许这里有人知道解决方案
if ($params["page_name"]=="index")
{
$filter = "";
if ($_SESSION['user_data']['type']!="admin")
{
$filter = " AND `enabled`=1 AND `visible`=1 ";
}
$sql = "SELECT a.* FROM
`".DB_PREFIX."items` a WHERE 1 $filter
ORDER BY `created` DESC
LIMIT ".($_SESSION['itemsPerPage']*($page-1)).",".$_SESSION['itemsPerPage'];
$items = $DB->getAll($sql);
for($i=0; $i<count($items); $i++)
{
$items[$i][third] = "";
$items[$i][thumb_rating] = rating_bar($items[$i]['id'], '5', 'static');
if($i%3==2)
$items[$i][third] = 'style="margin-right:0;"';
}
$smarty->assign("items", $items);
$sql = "SELECT COUNT(a.id) as `total` FROM
`".DB_PREFIX."items` a WHERE 1 $filter
";
$items = $DB->get($sql);
$total = $items['total'];
$smarty->assign("pagination", $DB->show_pagination($total, $page, $_SESSION['itemsPerPage']));
$output = $this->display(__FILE__, 'latestwallpapers.tpl');
}
return $output;
}
【问题讨论】:
-
我想说去掉 where 子句开头的
1 AND但我不确定 -
使用字符串连接来编写包含用户数据的查询是您未来非常糟糕的一天的秘诀。你确定你必须这样做吗? SQL injection bugs 一点也不好玩。
-
您的查询似乎缺少偏移量:
DESC LIMIT 0,。当然,在布尔上下文中将 1 评估为 true:MySQL 将任何非零、非 NULL 值评估为 TRUE。 参见 dev.mysql.com/doc/refman/5.6/en/logical-operators.html -
你确定 $_SESSION['itemsPerPage'] 有值吗?
-
我不确定,因为我不知道。