I seem to recall that it is possible to count all instances of a query
that is limited by $RecordsPerPage without repeating the same query. I
believe that COUNT() had to called immediately after the SELECT word but
I neglected to bookmark the source. Dummy!
I don't like the idea of count(*) over count() or something like that as
it seems rather slow fram what I read.
right now I do this:
$sql = "SELECT * FROM book
        WHERE id IN (SELECT bookID
        FROM book_author WHERE authID IN (SELECT author.id
        FROM author WHERE LEFT(last_name, 1 ) = '$Auth')) ";
$Count1 = mysql_num_rows(mysql_query($sql, $db));

$books = array();
$SQL = "SELECT * FROM book
        WHERE id IN (SELECT bookID
        FROM book_author WHERE authID IN (SELECT author.id
        FROM author WHERE LEFT(last_name, 1 ) = '$Auth'))
        ORDER BY $sort $dir
        LIMIT $offset, $records_per_page ";
        if ( ( $results = mysql_query($SQL, $db) ) !== false ) {
            while ( $row = mysql_fetch_assoc($results) ) {
                $books[$row['id']] = $row;
                }
            }
$Count = mysql_num_rows($results);

$Count gives me the actual rows for display - $Count1 gives me the total
rows available.

Can this be streamlined any?

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to