> He wants to know the maximum, like on a search for mysql at google it says
> "Results 1 - 10 of about 2,580,000." He wants to know that 2,580,000 number
> without doing another query. I don't think that's possible.

Of course it is. That's what I do all the time. That's what I was
talking about. I am looking at the result of my query. Then I
know how many I have. I won't and cannot show all of them, if
there are too many. So I check and repost that query with a LIMIT
constraint. Also, I figure out a navigation bar (like Google has)
to let the user jump between the pages or fetch one after the
other.

In addition, I give the user the opportunity to look at all
results if they want to, at own risk :-) but then they know why
it takes that long.

Next, I display the result one by one, so that they can start
reading while the others still build (for example with pictures).

For example, I did a search on Hannoveraner Horses:

http://pferdezeitung.de/Hannoveraner

I get 66 results at the time, but will show only 10. the
navigation bar says on the first page

10 results from 65, Nr. 1-10, next page
Result pages 1 2 3 4 5 6 7 total list

If you proceed to the next page, you will get a previous page
link, too, if you hit the last page, you will miss the next page
link.

All of this is packaged in 2 or 3 functions. In my working code,
I invoke it like this (again in my php lingo, spiced up with
PHPLIB's db-mysql.inc):

$q = "SELECT * FROM table
        WHERE $condition
        ORDER BY $order";
$db->query($q);

if ($db->nf()){//we have results
        checkLimits($q);//this rewrites the query, if necessary,
//i.e. if I have more results than defined - I don't have to
//think about this here
        while ($db->next_record()){//fetch the results
//if the query was rewritten and relaunched, we will now have
//less
               //.... do some stuff with it
               //generally, I collect things in an array $result
        }
}

$nav = makeLimitNav("$target?$getvars");//here I make the
//navigationbar - the only thing to know is the Link destination,
//normally the address we came from (phpself() in php-lingo), and
//maybe some parameters
echo $nav;//show it up front

tableArVerd($result, $cols);//this puts the resulting array in a
//nice table (this time in Verdana font style, to keep things
//short) with $cols columns - gives consistency in design, too,
//thoughout the site

echo $nav;//show the navbar at the end, too

I adopted this approach without problems to several other
projects. Works fine. Never think about it again. Just copy these
functions to the other project.

Now, it is obvious that all this should be encapsulated in a nice
class, but I am too busy and lazy to do this, but I bet there are
people out there who have done it. After all, everybody needs it,
right?

>> I'm not sure if I understand your problem. You should get exactly
>> $end results if there are more in the result set. Only if you
>> reach the end of your loop, you will get less.
>>
>> Example: You have 48 results and show them in batches of 10. Then
>> you should get 10, 10, 10, 10, 8 results if you show them from
>> start to end.
>>
>> So: I know I have 124 records and issue
>>
>> SELECT * FROM editions LIMIT 100, 30
>>
>> I get 24 results.


> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)

> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



-- 
Herzlich
Werner Stuerenburg            

_________________________________________________
ISIS Verlag, Teut 3, D-32683 Barntrup-Alverdissen
Tel 0(049) 5224-997 407 · Fax 0(049) 5224-997 409
http://pferdezeitung.de



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to