Jump to content

Pagination error


graham23s

Recommended Posts

Hi GUys,

 

Im coding in the pagination for a part of a script but im getting a mysql num rows error when applying the limit, even though there are rows in the table

 

code:

 

<?php
  case "edit_products";
  
  ###############################################
  # Pagination start
  ###############################################
  if(!isset($_GET['page'])){ 
 $page = 1; 
     } else { 
 $page = $_GET['page']; 
  } 
    
  $max = 10; 
  $num = $page * $max - $max;  
  ###############################################
  # Pagination start
  ###############################################

  // do a query to get the products //
  $q_prods = "SELECT * FROM `fcp_products`";
  $r_prods = mysql_query($q_prods);
  $n_prods = mysql_num_rows($r_prods);

  // pagination query //
  $q_pagination = "SELECT * FROM `fcp_products` LIMIT $num, $max"; 
  $r_pagination = mysql_query($q_pagination);
  $t_pagination = mysql_num_rows($r_pagination);

  if(($n_prods) == 0)
  {
   standard_message("Error","No products to display.");   
  }
  
   // display them //
  print("<table width='500' border='0' cellpadding='5' cellspacing='1' />\n");
  print("<tr>\n");
  print("<th colspan='4'>Products - [$n_prods]</th>\n");
  print("</tr>\n"); 
  print("<tr>\n");
  print("<th>ID</th><th>Product</th><th>Product Name</th><th>Action</th>\n");
  print("</tr>\n");  
  
  // loop //
  while($row = mysql_fetch_array($r_prods))
  {
   // vars //
   $p_id = $row['id'];
   $p_name = $row['product_name'];
   $p_thumb = $row['product_thumbnail'];
  
  print("<tr><td class='td_style' align='center'>$p_id</td><td class='td_style' align='center'><img src='products/thumbnails/$p_thumb'></td><td class='td_style' align='center'>$p_name</td><td class='td_style' align='center'>[<a class='smart_links' href='admin.php?page=master_edit&productid=$p_id'>EDIT</a>]-[<a class='smart_links' href='admin.php?page=master_delete&productid=$p_id'>DELETE</a>]</td></tr>");
  
  }   
  // end the table //
  print("<tr>\n");
  print("<td colspan='4' class='td_style' align='right'>&nbsp</td>\n");
  print("</tr>\n");
  print("</table><br />");
  
  ###############################################
  # Pagination end
  ###############################################

  ###############################################
  # Pagination end
  ###############################################

  break;
?>

 

the error occurs in this line:

 

<?php
$t_pagination = mysql_num_rows($r_pagination);
?>

 

have i done something wrong or overlooked something at all?

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/103122-pagination-error/
Share on other sites

do not try the '@' because all that does is allows the program to run with the error, it is a command that says 'ignore error' it does not fix them

 

your query is wrong, you didnt put the 'or die' command on it, if you had it would have told you you had an error in your query

 

try this

 

$q_pagination = "SELECT * FROM `fcp_products` LIMIT '$num', '$max'"; 

 

you must use single quotes around php variables in the query syntax

 

sorry just spotted the error in my own co=de for the error

 

$r_pagination = mysql_query($q_pagination) or die ("Error in query" . mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/103122-pagination-error/#findComment-528253
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.