English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Pour utiliser la pagination MySQL, regardons d'abord comment utiliser la commande CREATE pour créer une table.
mysql>CREATE table RowCountDemo -> ( -> ID int, -> Nom varchar(100) -> );
Les enregistrements sont insérés avec l'aide de la commande INSERT.
mysql>INSERT into RowCountDemo values(1, 'Larry'); mysql>INSERT into RowCountDemo values(2, 'John'); mysql>INSERT into RowCountDemo values(3, 'Bela'); mysql>INSERT into RowCountDemo values(4, 'Jack'); mysql>INSERT into RowCountDemo values(5, 'Eric'); mysql>INSERT into RowCountDemo values(6, 'Rami'); mysql>INSERT into RowCountDemo values(7, 'Sam'); mysql>INSERT into RowCountDemo values(8, 'Maike'); mysql>INSERT into RowCountDemo values(9, 'Rocio'); mysql>INSERT into RowCountDemo values(10, 'Gavin');
Affichez tous les enregistrements avec l'aide de l'instruction SELECT.
mysql>SELECT* from RowCountDemo;
Voici la sortie.
+------+-------+ | ID | Nom | +------+-------+ | 1 | Larry | | 2 | John | | 3 | Bela | | 4 | Jack | | 5 | Eric | | 6 | Rami | | 7 | Sam | | 8 | Maike | | 9 | Rocio | | 10 | Gavin | +------+-------+ 10 rows in set (0.00 sec)
Maintenant, regardons la syntaxe de pagination sans requêtes redondantes.
SELECT column_name From `yourTableName` WHERE someCondition LIMIT value1, value2;
Maintenant, appliquons la syntaxe ci-dessus.
mysql> SELECT ID,Name FROM `RowCountDemo` WHERE ID > 0 LIMIT 0, 11;
Ceci est la sortie de la requête ci-dessus.
+------+-------+ | ID | Nom | +------+-------+ | 1 | Larry | | 2 | John | | 3 | Bela | | 4 | Jack | | 5 | Eric | | 6 | Rami | | 7 | Sam | | 8 | Maike | | 9 | Rocio | | 10 | Gavin | +------+-------+ 10 rows in set (0.00 sec)