View Single Post
  #9 (permalink)  
Old 06-26-2008, 03:05 AM
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 247
Quote:
Originally Posted by curtiss View Post
I'm sorry, Gil, but once again I am really having trouble understanding what question you are asking.

However, as a start, there is a minor problem with the math in your code. $end should be equal to $page*$perpage-1, otherwise you are going to repeat something on each page. For example:

$perpage = 10;
$page = 1;
would mean
$end = 10;
$start = 0; (which will give you a total of eleven results)

$perpage = 10;
$page = 2;
would mean
$end = 20;
$start = 10; (which you already showed on page 1)

If you are looking for a way to find out the total number of records that would be returned, you're not going to be able to do so with your current SQL query. You are limiting your results to 10 (or 11) records with each execution of the SQL query.

In order to find the total, you are going to need to remove the LIMIT phrase from the SQL query and you should probably use the COUNT property in your SQL query rather than trying to use mysql_num_rows.

Therefore, your second SQL query would look something like "SELECT COUNT(*) totalrows FROM dbname WHERE 1=1..." without the limit at the end. Then, you would access the total number of rows by pulling the "totalrows" key out of the result.
What is totalrows? I removed:
$sql.= " LIMIT " . $start . ", " . $perpage;
and inserted:
$sql="SELECT count(*) totalrows FROM bible WHERE 1=1 AND";

But got 1: as an answer.
Reply With Quote