开发者

PHP - Pagination - Why am I getting this error : Unable to jump to row 0 on MySQL result index 13?

I am having problems w开发者_开发百科ith paging some results drawn from a Mysql database.

This is the code relating to the pagination:

    $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>
';

I am adapting it from this tutorial : http://www.webdesign-4-beginners.co.uk/web-design-blog/2009/12/mysql-results-page-numbering/

I am getting the following mysql error:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 13 in /path-to/orders-layout.php on line 302

Also, when viewing page 2 of two, the result count is blank, and the pagination does not show the page numbers, only "previous page". On page 1 of 2, everything looks as it should? Does anyone have any idea what I have done wrong with this?


You must not limit your totals query. Remove limit from it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜