RE: [PHP-ES] limitar select
| From: | Iñigo López-Castro | Date: | Tue, 06 Aug 2002 12:02:29 +0000 |
| Subject: | RE: [PHP-ES] limitar select | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-25684@lists.php.net to get a copy of this message | ||
holas........
he encontrado esto en google.....
http://dbi.interbase.or.id/faq.html
----------------------------------------------------------------
How can I perform LIMIT clause as I usually do in MySQL?
LIMIT clause let users to fetch only a portion rather than the whole records as the result of a
query. This is particularly
efficient and useful for paging feature on web pages, where users can navigate back and forth
between pages. Using InterBase
(Firebird is explained later), this can be emulated by writing a stored procedure. For example, to
display a portion of table_forum,
first create the following procedure:
CREATE PROCEDURE PAGING_FORUM (start INTEGER, num INTEGER)
RETURNS (id INTEGER, title VARCHAR(255), ctime DATE, author VARCHAR(255))
AS
DECLARE VARIABLE counter INTEGER;
BEGIN
counter = 0;
FOR SELECT id, title, ctime, author FROM table_forum ORDER BY ctime
INTO :id, :title, :ctime, :author
DO
BEGIN
IF (counter = :start + :num) THEN EXIT;
ELSE
IF (counter >= :start) THEN SUSPEND;
counter = counter + 1;
END
END !!
SET TERM ; !!
And within your application:
# fetch record 1 - 5:
$res = $dbh->selectall_arrayref("SELECT * FROM paging_forum(0,5)");
# fetch record 6 - 10:
$res = $dbh->selectall_arrayref("SELECT * FROM paging_forum(5,5)");
But never expect this to work:
$sth = $dbh->prepare(
"EXECUTE PROCEDURE paging_forum(5,5) RETURNING_VALUES :id, :title, :ctime,
:author");
With Firebird 1 RCx and later, you can use SELECT FIRST:
SELECT FIRST 10 SKIP 30 * FROM table_forum;
FIRST x and SKIP x are both optional. FIRST limits the number of rows to return, SKIP should be
self-explanatory.
--------------------------------------------------------
espero que te sirva, no parece dificil de implementar...
salu2
----- Original Message -----
From: Xavi Sanz
To: Lista phpes ; lista php
Sent: Tuesday, August 06, 2002 12:52 PM
Subject: [PHP-ES] limitar select
buenas,
alguien tiene idea de como limitar los resultados de una select a un numero especifico d registros?
por ejemplo k solo devuelva los 15 primeros registros encontrados por la select
por cierto utilizo interbase, k no tiene la cantidad de funciones d mysql por ejemplo
solo saber si hay algun comando especifico para limitar el numero d registros retornados
mersi a todos