开发者

PHP - Pagination - Why am I getting this error : not found in MySQL result index 14?

开发者 https://www.devze.com 2023-04-02 21:18 出处:网络
I am having problems with paging some results drawn from a Mysql database. This is the code relating to the pagination:

I am having problems with paging some results drawn from a Mysql database.

This is the code relating to the pagination:

$max_results = 5; //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)开发者_如何学C
            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>
';

// Build paginator
if($pg > 1){ $prev = ($pg - 1); // Previous Link
$paginator ='<a href="'.$_SERVER['PHP_SELF'].'?pg='.$prev.'">"Previous page</a>'; }
for($i = 1; $i <= $total_pgs; $i++){ /// Numbers
if(($pg) == $i) { $paginator .= "<i>$i</i> "; } else {
$paginator .='<a href="'.$_SERVER['PHP_SELF'].'?pg='.$i.'">$i</a> '; }}
if($pg < $total_pgs){ $next = ($pg + 1); // Next Link
$paginator .='<a href="'.$_SERVER['PHP_SELF'].'?pg='.$next.'">"Next page."</a>'; }

$pageContent .= '
<p>'.$paginator.'</p>
';

/// Display results
if ($num_sql > 0 ) {$i=0;
while ($i < $num_sql) {
$holsite = mysql_result($result1,$i,"holsite");
$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 5 times (5 is the number of pages there should be):

Warning: mysql_result() [function.mysql-result]: holsite not found in MySQL result index 14 in /path-to/orders-layout.php on line 459

Does anyone have any idea what I have done wrong with this?


Your problem is that your query here

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

Doesn't contain any reference to a column holsite that you are looking for at the bottom. (the 3rd parameter of mysql_result is the field name)

$holsite = mysql_result($result1,$i,"holsite");

Either you're not pulling out holsite in the query, or you've gotten the name of the column wrong when you're setting $holsite.

0

精彩评论

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

关注公众号