Обсуждение: Can This be done
Hi! Is it possible for example I have one db with 100.000 entries. I select some data, let say about 1.000. Now i want this data show on page by pages. I use limit and ofset for this. But how can i know how much is all the records. Because i want to print also how many hits were but i don't want get all the rows at once. Is there any function for this or i have to make 2 queries. -- tia, Uros
On 5/12/02 3:22 PM, "Uros Gruber" <uros@sir-mag.com> wrote: > Hi! > > Is it possible for example I have one db with 100.000 > entries. I select some data, let say about 1.000. Now i want > this data show on page by pages. > > I use limit and ofset for this. But how can i know how much > is all the records. Because i want to print also how many > hits were but i don't want get all the rows at once. > > Is there any function for this or i have to make 2 queries. In most implementations I've seen, which is mostly middleware such as PHP, if you aren't going to get all the rows at once, you need two queries. The "function" that you want, that tells you the number of rows matching criteria X, is, after all, a SELECT statement ... :-> -- sgl ======================================================= Steve Lane Vice President Chris Moyer Consulting, Inc. 833 West Chicago Ave Suite 203 Voice: (312) 433-2421 Email: slane@fmpro.com Fax: (312) 850-3930 Web: http://www.fmpro.com =======================================================
Hi, I know that select return a number of records, but i i use LIMIT i can't know how many row actualy is, because it's alway smaller than limit. Only solution I know for now is with 2 queryes. First query to get all the data, and than second with limit. But this is not something i want. -- bye, Uros mailto:uros@sir-mag.com Monday, May 13, 2002, 7:47:01 PM, you wrote: SL> On 5/12/02 3:22 PM, "Uros Gruber" <uros@sir-mag.com> wrote: >> Hi! >> >> Is it possible for example I have one db with 100.000 >> entries. I select some data, let say about 1.000. Now i want >> this data show on page by pages. >> >> I use limit and ofset for this. But how can i know how much >> is all the records. Because i want to print also how many >> hits were but i don't want get all the rows at once. >> >> Is there any function for this or i have to make 2 queries. SL> In most implementations I've seen, which is mostly middleware such as PHP, SL> if you aren't going to get all the rows at once, you need two queries. The SL> "function" that you want, that tells you the number of rows matching SL> criteria X, is, after all, a SELECT statement ... :-> SL> -- sgl SL> ======================================================= SL> Steve Lane SL> Vice President SL> Chris Moyer Consulting, Inc. SL> 833 West Chicago Ave Suite 203 SL> Voice: (312) 433-2421 Email: slane@fmpro.com SL> Fax: (312) 850-3930 Web: http://www.fmpro.com SL> =======================================================
On Mon, May 13, 2002 at 08:23:29PM +0200, Uros Gruber wrote: > Hi, > > I know that select return a number of records, but i i use > LIMIT i can't know how many row actualy is, because it's > alway smaller than limit. > > Only solution I know for now is with 2 queryes. First query > to get all the data, and than second with limit. But this is > not something i want. I'm afraid you're stuck here. To work out how many rows there are, the system has to evaluate the entire query. And if you're evaluating the entire query, you may as well use the entire result set. It may be helpful to decide whether you really need the number of rows. For example, Google only provides an estimate unless it really is a small number of matches. If all you want it know whether to provide a next link, do limit (number of rows+1). If the extra now is there, provide a next link. HTH, -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > Canada, Mexico, and Australia form the Axis of Nations That > Are Actually Quite Nice But Secretly Have Nasty Thoughts About America