{"id":3985,"date":"2017-09-13T06:50:59","date_gmt":"2017-09-13T13:50:59","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=3985"},"modified":"2025-06-13T21:28:55","modified_gmt":"2025-06-14T04:28:55","slug":"pagination-couchbase-server-n1ql-php","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/","title":{"rendered":"Pagination in Couchbase Server with N1QL and PHP"},"content":{"rendered":"<p>Onwuka Gideon is a freelance full stack developer with years of experience designing and coding web applications and solving complex problems. He loves security, writing, and discussing new technology.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3983\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/09\/18485569_1371908909572883_6954592115736688669_n.jpg\" alt=\"18485569 1371908909572883 6954592115736688669 n\" width=\"268\" height=\"268\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/18485569_1371908909572883_6954592115736688669_n.jpg 160w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/18485569_1371908909572883_6954592115736688669_n-150x150.jpg 150w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/18485569_1371908909572883_6954592115736688669_n-65x65.jpg 65w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/18485569_1371908909572883_6954592115736688669_n-50x50.jpg 50w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/18485569_1371908909572883_6954592115736688669_n-20x20.jpg 20w\" sizes=\"auto, (max-width: 268px) 100vw, 268px\" \/><\/p>\n<p>When building applications that deal with a large number of documents, it is important to use pagination to get rows by page.<\/p>\n<p>In this article, I&#8217;ll demonstrate how to implement pagination when working with N1QL and PHP.<\/p>\n<h4>A little about N1QL<\/h4>\n<p>Couchbase N1QL is a declarative query language that extends SQL for JSON. You can query data via native framework and language integration, a fluent API, or the JDBC\/ODBC drivers.\u00a0N1QL\u00a0gives developers an expressive, powerful, and complete language for querying and manipulating data.<\/p>\n<h5>Prerequisites<\/h5>\n<ul>\n<li>Basic knowledge of Couchbase and have it set up on your server (<u><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/4.0\/getting-started\/installing.html\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase installation<\/a><\/u>)<\/li>\n<li>Basic knowledge of N1QL<\/li>\n<li>Basic knowledge of PHP (optional, since any language can be used)<\/li>\n<li>An available Couchbase SDK\u00a0(<u><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/sdk\/php\/start-using-sdk.html\" target=\"_blank\" rel=\"noopener noreferrer\">Go here<\/a><\/u>)<\/li>\n<\/ul>\n<h4>What we would build<\/h4>\n<p>For the purpose of this article, we&#8217;ll quickly set up a PHP environment where we&#8217;ll basically pull data from the database, paginate the data, and display it.<\/p>\n<p>Setting up the environment<\/p>\n<p>Step 1: create a new bucket<\/p>\n<p>Log in to your Couchbase admin area\u00a0and create a new bucket name `commenting`.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1123\" height=\"272\" class=\"wp-image-3984\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-08-20-21-25-56.png\" alt=\"Screenshot from 2017 08 20 21 25 56\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/Screenshot-from-2017-08-20-21-25-56.png 1123w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/Screenshot-from-2017-08-20-21-25-56-300x73.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/Screenshot-from-2017-08-20-21-25-56-1024x248.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/Screenshot-from-2017-08-20-21-25-56-768x186.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/Screenshot-from-2017-08-20-21-25-56-20x5.png 20w\" sizes=\"auto, (max-width: 1123px) 100vw, 1123px\" \/><\/p>\n<p>Step 2: create an index for the new bucket: `commenting`<\/p>\n<p>Click on the query tab, insert the query listed below, and click on execute.<\/p>\n<pre class=\"lang:default decode:true \">create primary index on `commenting` using gsi;\r\n<\/pre>\n<p>If everything goes smoothly, we are good to start creating documents.<\/p>\n<p>Step 3: clone the project starter file<\/p>\n<p>I&#8217;ve created the basic file structure of the files we&#8217;ll be using for this tutorial.<\/p>\n<p>Open up your command line, then clone the repository from github.<\/p>\n<pre class=\"lang:default decode:true \">$\u00a0git clone\u00a0git@github.com:dongido001\/php-couchbase-pagination_complete.git\r\n<\/pre>\n<p>Now, open up the file you just cloned in your browser. You should see the following page:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"627\" class=\"wp-image-3982\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/09\/page.png\" alt=\"page\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/page.png 1600w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/page-300x118.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/page-1024x401.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/page-768x301.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/page-1536x602.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/page-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/page-1320x517.png 1320w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/p>\n<h2>The file structure<\/h2>\n<p>The repository you just cloned contains 3 PHP files: `config.php`, `db.php`, and `index.php`.<\/p>\n<p>The `config.php` file is where we define the information of our database:<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php\r\n\/\/some configs\r\ndefine(\"C_USERNAMAE\", \"Administrator\");\r\ndefine(\"C_PASSWORD\", \"password\");\r\ndefine(\"C_URL\", \"https:\/\/127.0.0.1:8091\/\"); \/\/eg: localhost:8091\r\ndefine(\"DEFAULT_BUCKET\", \"commenting\");<\/pre>\n<p>In the `db.php`, \u00a0we connected to Couchbase and opened a bucket.You should change the details to correspond to your Couchbase information.<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\n\r\n$authenticator = new\u00a0\\Couchbase\\ClassicAuthenticator();\r\n$authenticator-&gt;cluster(C_USERNAMAE, C_PASSWORD);\r\n\r\n$cluster = new\u00a0\\Couchbase\\Cluster(C_URL);\r\n\r\n$cluster-&gt;authenticate($authenticator);\r\n\r\n$bucket = $cluster-&gt;openBucket(DEFAULT_BUCKET);\r\n\r\nIn the `index.php`, we have some PHP code at the top of the file and at the bottom, we also<\/pre>\n<p>have some HTML code.<\/p>\n<pre class=\"lang:default decode:true\">\/\/index.php\r\n\r\n&lt;?php\r\n\r\n\/\/include config details\r\n\r\nrequire_once('config.php');\r\n\r\n\/\/include connection to the database.\r\n\r\nrequire_once('db.php');\r\n\r\nif( $_SERVER['REQUEST_METHOD'] == \"POST\"){\r\n\r\n$uid = uniqid();\r\n\r\n$comment = [\r\n\r\n\"_id\"\u00a0 \u00a0 \u00a0 \u00a0 =&gt; $uid,\r\n\"name\"\u00a0 \u00a0 \u00a0 \u00a0=&gt; $_POST[\"name\"],\r\n\"comment\"\u00a0 \u00a0 =&gt; $_POST[\"comment\"],\r\n\"created_at\"\u00a0=&gt; date(\"Y-m-d H:i:s\")\r\n];\r\n\r\n$bucket-&gt;insert($uid, $comment);\r\n\r\n}\r\n\r\n?&gt;\r\n\r\n...<\/pre>\n<p>I included the two files, `config.php` and `db.php` then I wrote logic to insert some comments into the database when the form is submitted.<\/p>\n<pre class=\"lang:default decode:true \">\/\/index.php\r\n\r\n...\r\n\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n&lt;!-- Required meta tags --&gt;\r\n&lt;meta charset=\"utf-8\"&gt;\r\n&lt;meta name=\"viewport\"\u00a0content=\"width=device-width, initial-scale=1, shrink-to-fit=no\"&gt;\r\n\r\n&lt;!-- Bootstrap CSS --&gt;\r\n&lt;link rel=\"stylesheet\"\u00a0href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/4.0.0-beta\/css\/bootstrap.min.css\"\u00a0integrity=\"sha384-\/Y6pD6FV\/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M\"\u00a0crossorigin=\"anonymous\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;div class=\"container\"&gt;\r\n\r\n&lt;div\u00a0class=\"container\" style=\"margin-left: auto; margin-right: auto; width: 400px;\"&gt;\r\n&lt;h4\u00a0class=\"text-center\"&gt;Add\u00a0a\u00a0comment&lt;\/h4&gt;\r\n\r\n&lt;form\u00a0action=\"\" method=\"POST\"&gt;\r\n&lt;div\u00a0class=\"form-group\"&gt;\r\n&lt;label\u00a0for=\"name\"&gt;Name:&lt;\/label&gt;\r\n&lt;input\u00a0type=\"text\" class=\"form-control\" name=\"name\" required&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;div\u00a0class=\"form-group\"&gt;\r\n&lt;label\u00a0for=\"comment\"&gt;Comment:&lt;\/label&gt;\r\n&lt;textarea\u00a0class=\"form-control\" rows=\"5\" name=\"comment\" required&gt; &lt;\/textarea&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;button\u00a0type=\"submit\" class=\"btn\u00a0btn-primary\"&gt;Submit&lt;\/button&gt;\r\n&lt;\/form&gt; &lt;br\u00a0\/&gt;\r\n\r\n&lt;div\u00a0&gt;\r\n&lt;h4\u00a0class=\"text-center\"&gt;Listing\u00a0comments&lt;\/h4&gt;\r\n\r\n&lt;\/div&gt;\r\n\r\n&lt;div\u00a0id=\"pagination\"&gt;\r\n\r\n&lt;\/div&gt;\r\n\r\n&lt;\/div&gt;\r\n\r\n&lt;\/div&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p>The HTML code displays a form for adding and listing comments.<\/p>\n<p>Now let&#8217;s get started!<\/p>\n<p>Add as many comments from the page as you like. We will be paginating that data soon.<\/p>\n<p>Fetch paginated content in the database<\/p>\n<p>Add the following to the header part of `index.php` that is below every PHP code at the top.<\/p>\n<pre class=\"lang:default decode:true\">&amp;nbsp;\/\/Select all contentin our query \r\n\r\n$no_per_page = 4; \/\/This is the number of Items we want per page\r\n\r\n&amp;nbsp;$current_page = (isset($_GET['page_id'])) ? $_GET['page_id'] : 1; \/\/Gets the current page, if not set, default to page 1\r\n\r\n$skip = ($current_page - 1) * $no_per_page; \/\/Gets the total number of page we want to skip when making request. When we are on page one, We don't need to skip any Item.\r\n\r\n$query = \\Couchbase\\N1qlQuery::fromString(\"SELECT * FROM `commenting` &amp;nbsp;LIMIT $no_per_page OFFSET $skip\");\r\n\r\n$result = $bucket-&gt;query($query);\r\n\r\n\/\/count total number of result in the database\r\n\r\n$total = $bucket-&gt;query(\\Couchbase\\N1qlQuery::fromString(\"SELECT COUNT(comment) total FROM `commenting`\"));\r\n\r\n$total = $total-&gt;rows[0]-&gt;total;\r\n\r\n$number_of_pages = ceil( $total\/$no_per_page ); \/\/calculate number of pages<\/pre>\n<p>I&#8217;ve added comments to the code above, which describes what each does. Here we also used `LIMIT` AND `OFFSET` which enabled us to LIMIT the number of results each query is meant to return. The OFFSET was used to skip over an amount of data when querying depending on the page number we are currently accessing.<\/p>\n<p>`LIMIT`: The LIMIT clause specifies the maximum number of objects that can be returned in a result set by SELECT. A negative value or a value greater than 9223372036854775295 (result of 1\u00a0&#8211; 512) is considered as LIMIT 0.<\/p>\n<p>`OFFSET`: The OFFSET clause specifies a number of objects to be skipped. If a LIMIT clause is also present, the OFFSET is applied prior to the LIMIT. The OFFSET value must be a non-negative integer.<\/p>\n<p>Populate the result of the query to the page<\/p>\n<p>Add the code below to `index.php` inside this tag, immediately after `&lt;h4 class=&#8221;text-center&#8221;&gt;Listing comments&lt;\/h4&gt; `.<\/p>\n<pre class=\"lang:default decode:true \">\u00a0 \u00a0 \u00a0 &lt;?php\u00a0foreach( $result-&gt;rows as\u00a0$comment ):?&gt;\r\n&lt;div&gt;\r\n&lt;div class=\"alert\u00a0alert-success\" role=\"alert\"&gt;\r\n&lt;h5\u00a0class=\"alert-heading\"&gt; By: &lt;?=$comment-&gt;commenting-&gt;name?&gt;, Created\u00a0At: &lt;?=$comment-&gt;commenting-&gt;created_at?&gt; &lt;\/h5&gt;&lt;br&gt;\r\n&lt;p&gt; &lt;?=$comment-&gt;commenting-&gt;comment?&gt;&lt;\/p&gt;\r\n&lt;hr&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;\/div&gt;\r\n&lt;?php\u00a0endforeach; ?&gt;\r\n\r\n<\/pre>\n<p>Add the paginated link<\/p>\n<p>Add the code below in between this html tag `&lt;div id=&#8221;pagination&#8221;&gt; &lt;\/div&gt;` at the bottom part of index.php.<\/p>\n<table style=\"height: 225px\" width=\"701\">\n<tbody>\n<tr>\n<td>\n<pre class=\"lang:default decode:true \">\u00a0 \u00a0 &lt;nav aria-label=\"Page navigation example\"&gt;\r\n&lt;ul class=\"pagination\"&gt;\r\n&lt;?php\u00a0for($i\u00a0= 1; $i\u00a0&lt;= $number_of_pages; $i++): ?&gt;\r\n&lt;li\u00a0class=\"page-item\"&gt;&lt;a\u00a0class=\"page-link\" href=\"?page_id=&lt;?=$i?&gt;\"&gt;&lt;?=$i?&gt;&lt;\/a&gt;&lt;\/li&gt;\r\n&lt;?php\u00a0endfor; ?&gt;\r\n&lt;\/ul&gt;\r\n&lt;\/nav&gt;<\/pre>\n<p>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Here we are just printing out the number of pages to the page.<\/p>\n<p>Yeah! Our pagination is working now.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"856\" class=\"wp-image-3981\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/09\/Peek-2017-08-23-19-35.gif\" alt=\"Peek 2017 08 23 19 35\" \/><\/p>\n<h2><\/h2>\n<h2><\/h2>\n<h2>Conclusion<\/h2>\n<p>In this article, you have learned how to implement pagination using N1QL. We&#8217;ve also reviewed `OFFSET` and `LIMIT` and how to basically run queries in Couchbase using N1QL. You can get the complete app here: (`git@github.com:dongido001\/php-couchbase-pagination_complete.git`)<\/p>\n<p>Thanks for reading. Let me know what you think or if you have any questions.<\/p>\n<p><a href=\"https:\/\/www.couchbase.com\/community\/community-writers-program\/\"><em>This post is part of the Couchbase Community Writing Program<\/em><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Onwuka Gideon is a freelance full stack developer with years of experience designing and coding web applications and solving complex problems. He loves security, writing, and discussing new technology. When building applications that deal with a large number of documents, [&hellip;]<\/p>\n","protected":false},"author":53,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1816,9408,1812],"tags":[1261,2044],"ppma_author":[9026],"class_list":["post-3985","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-server","category-php","category-n1ql-query","tag-json","tag-paging"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.0 (Yoast SEO v26.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Pagination in Couchbase Server with N1QL and PHP - The Couchbase Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pagination in Couchbase Server with N1QL and PHP\" \/>\n<meta property=\"og:description\" content=\"Onwuka Gideon is a freelance full stack developer with years of experience designing and coding web applications and solving complex problems. He loves security, writing, and discussing new technology. When building applications that deal with a large number of documents, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-13T13:50:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:28:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/18485569_1371908909572883_6954592115736688669_n.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"160\" \/>\n\t<meta property=\"og:image:height\" content=\"160\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Laura Czajkowski, Developer Community Manager, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Laura Czajkowski, Developer Community Manager, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/\"},\"author\":{\"name\":\"Laura Czajkowski, Developer Community Manager, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220\"},\"headline\":\"Pagination in Couchbase Server with N1QL and PHP\",\"datePublished\":\"2017-09-13T13:50:59+00:00\",\"dateModified\":\"2025-06-14T04:28:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/\"},\"wordCount\":725,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"JSON\",\"Paging\"],\"articleSection\":[\"Couchbase Server\",\"PHP\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/\",\"name\":\"Pagination in Couchbase Server with N1QL and PHP - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2017-09-13T13:50:59+00:00\",\"dateModified\":\"2025-06-14T04:28:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pagination in Couchbase Server with N1QL and PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220\",\"name\":\"Laura Czajkowski, Developer Community Manager, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/9deb07d5daaa00220534c31768bc4409\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g\",\"caption\":\"Laura Czajkowski, Developer Community Manager, Couchbase\"},\"description\":\"Laura Czajkowski is the Snr. Developer Community Manager at Couchbase overseeing the community. She\u2019s responsible for our monthly developer newsletter.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/laura-czajkowski\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Pagination in Couchbase Server with N1QL and PHP - The Couchbase Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/","og_locale":"en_US","og_type":"article","og_title":"Pagination in Couchbase Server with N1QL and PHP","og_description":"Onwuka Gideon is a freelance full stack developer with years of experience designing and coding web applications and solving complex problems. He loves security, writing, and discussing new technology. When building applications that deal with a large number of documents, [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/","og_site_name":"The Couchbase Blog","article_published_time":"2017-09-13T13:50:59+00:00","article_modified_time":"2025-06-14T04:28:55+00:00","og_image":[{"width":160,"height":160,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/09\/18485569_1371908909572883_6954592115736688669_n.jpg","type":"image\/jpeg"}],"author":"Laura Czajkowski, Developer Community Manager, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Laura Czajkowski, Developer Community Manager, Couchbase","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/"},"author":{"name":"Laura Czajkowski, Developer Community Manager, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220"},"headline":"Pagination in Couchbase Server with N1QL and PHP","datePublished":"2017-09-13T13:50:59+00:00","dateModified":"2025-06-14T04:28:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/"},"wordCount":725,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["JSON","Paging"],"articleSection":["Couchbase Server","PHP","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/","url":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/","name":"Pagination in Couchbase Server with N1QL and PHP - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2017-09-13T13:50:59+00:00","dateModified":"2025-06-14T04:28:55+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/pagination-couchbase-server-n1ql-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Pagination in Couchbase Server with N1QL and PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220","name":"Laura Czajkowski, Developer Community Manager, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/9deb07d5daaa00220534c31768bc4409","url":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","caption":"Laura Czajkowski, Developer Community Manager, Couchbase"},"description":"Laura Czajkowski is the Snr. Developer Community Manager at Couchbase overseeing the community. She\u2019s responsible for our monthly developer newsletter.","url":"https:\/\/www.couchbase.com\/blog\/author\/laura-czajkowski\/"}]}},"authors":[{"term_id":9026,"user_id":53,"is_guest":0,"slug":"laura-czajkowski","display_name":"Laura Czajkowski, Developer Community Manager, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","author_category":"","last_name":"Czajkowski","first_name":"Laura","job_title":"","user_url":"","description":"Laura Czajkowski is the Snr. Developer Community Manager at Couchbase overseeing the community. She\u2019s responsible for our monthly developer newsletter."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/3985","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=3985"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/3985\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=3985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=3985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=3985"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=3985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}