我在分析从Mysql数据库中提取的一些结果时遇到了问题。
这是与分页相关的代码:
$max_results = 20; //Max listed query results
if(!isset($_GET['pg'])){ $pg = 1; } else { $pg = $_GET['pg']; }
$from = (($pg * $max_results) - $max_results);
/// START of MySQL results – Page numbering
$space_separated = implode(" ", $keywords_array);
/// Count total
$totals = mysql_result(mysql_query("SELECT COUNT(id)
FROM products
WHERE MATCH (`desc`)
AGAINST ('".$space_separated."' IN BOOLEAN MODE)
ORDER BY `desc`
LIMIT $from, $max_results"),0);
$total_pgs = ceil($totals / $max_results);
$tempVar = 0; //Used in the generation of order form
///Now we search for our search term, in the field the user specified
// Page limiter & result builder
$dataQuery = "SELECT id, `desc`, price1, pack, measure, quantity
FROM products
WHERE MATCH (`desc`)
AGAINST ('".$space_separated."' IN BOOLEAN MODE)
ORDER BY `desc`
LIMIT $from, $max_results";
$result1 = mysql_query($dataQuery);
$num_sql = mysql_num_rows ($result1);
$data = mysql_query($dataQuery) or die(mysql_error());
$pageContent .= '
<div>
<p>Results: '.$totals.'</p>
<p>Viewing page '.$pg.' of '.$total_pgs.'</p>
</div>
<!-- end .aliLeft --></div>
';
$pageContent .= '
<p>'.$paginator.'</p>
';
/// Display results
if ($num_sql > 0 ) {$i=0;
while ($i < $num_sql) {
$holsite = mysql_result($result1,$i,"desc");
$pageContent .= ''.$holsite.'';
++$i;}}
$pageContent .= '
<p>'.$paginator.'</p>
';
我正在修改本教程:http://www.webdesign-4-beginners.co.uk/web-design-blog/2009/12/mysql-results-page-numbering/
我收到以下mysql错误:
警告:mysql_result()[function.mysql-result]:无法跳转到第302行的/path-to/orders-layout.php中MySQL结果索引13的第0行
此外,当查看第2页的第2页时,结果计数为空白,并且分页不显示页码,仅显示“上一页”。在第1页的第2页,一切看起来应该如何? 有谁知道我做错了什么?
答案 0 :(得分:1)
您不得限制总计查询。从中移除限制。