{"id":20473,"date":"2022-11-09T19:29:33","date_gmt":"2022-11-09T13:59:33","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/"},"modified":"2022-11-09T19:29:33","modified_gmt":"2022-11-09T13:59:33","slug":"solved-pagination-data","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/","title":{"rendered":"[Solved] Pagination data"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-39889881\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"39889881\" data-parentid=\"39889747\" data-score=\"1\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>You need to study their code more, dont just copy&amp;paste. You told the program to <code>echo<\/code> those variables and it echoed them for you. In the tutorial they seem to store all the &#8216;paginatable&#8217; data in the $list, so you need to look into that. <code>$id = $row[\"id\"];<\/code> prints <code>id<\/code> column from the current table in mySql<\/p>\n<p>Edit: I will try to explain what most of the lines in the website you provided do.<br \/>\nI do not know if you are familiar with SQL, but you need to know basics of mysql to be able to create your pagination script.<\/p>\n<pre><code>$sql = \"SELECT COUNT(id) FROM testimonials WHERE approved='1'\";\n$query = mysqli_query($db_conx, $sql);\n$row = mysqli_fetch_row($query);\n<\/code><\/pre>\n<p>$sql prepares the sql statement that will count entries in the mysql table testimonials whose approved column is set to 1. Then $query uses the mysqli_query to process the sql statement ($db_con is declared in mysqli_connection.php, it tells the server how to connect to the database). <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.w3schools.com\/php\/php_mysql_select.asp\">Check here<\/a><\/p>\n<p>$row is an array and here it only consists of 1 element &#8211; the number of entries in testimonials with approved=1. Therefore $rows is declared and it is set to that number &#8212; $row[0].<\/p>\n<pre><code>$page_rows = 10;\n$last = ceil($rows\/$page_rows);\n<\/code><\/pre>\n<p><code>ceil<\/code> is a php function that rounds a number up to the closest integer (0.4 -&gt; 1, 5.1 -&gt; 6). $page_rows tells how many testimonials you want to be displayed per page, so $last takes total number of testimonials and divides them by 10 and the result is the number of pages. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.w3schools.com\/php\/func_math_ceil.asp\">Check here<\/a><\/p>\n<p>I will skip the next few lines of their code because they are very straightforward.<\/p>\n<pre><code>if(isset($_GET['pn'])){\n    $pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);\n}\n<\/code><\/pre>\n<p>$_GET is a superglobal that collects data from the URL. If you have 18 testimonials, if you go to page 2, the url will take the form of &#8220;your_website\/?pn=2&#8221;. So here $pagenum is set to the value of the superglobal <code>pn<\/code> only if it is set (because by default, when you are on page 1 <code>pn<\/code> is not set) <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.w3schools.com\/php\/php_superglobals.asp\">Check here<\/a><\/p>\n<pre><code>$limit=\"LIMIT \" .($pagenum - 1) * $page_rows .',' .$page_rows;\n<\/code><\/pre>\n<p>This is also an SQL statement that tells the server that the number of testimonials to be shown should be limited to 10 <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.w3schools.com\/php\/php_mysql_select_limit.asp\">Check here<\/a><\/p>\n<pre><code>$sql = \"SELECT id, firstname, lastname, datemade FROM testimonials WHERE approved='1' ORDER BY id DESC $limit\";\n$query = mysqli_query($db_conx, $sql);\n<\/code><\/pre>\n<p>These two are once again mysql statements that select the columns <code>id, firstname, lastname, datemade<\/code> from your table with approved=1 and order all of the entries by their id in reverse order <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.w3schools.com\/sql\/sql_orderby.asp\">Check here<\/a><\/p>\n<p>Now I am pretty sure after you study all of the above, you will be able to figure out what the next lines do (their comments should help as well).<\/p>\n<p>Important part is here:<\/p>\n<pre><code>while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){\n    $id = $row[\"id\"];\n    $firstname = $row[\"firstname\"];\n    $lastname = $row[\"lastname\"];\n    $datemade = $row[\"datemade\"];\n    $datemade = strftime(\"%b %d, %Y\", strtotime($datemade));\n    $list .= '&lt;p&gt;&lt;a href=\"https:\/\/stackoverflow.com\/questions\/39889747\/testimonial.php?id=\".$id.'\"&gt;'.$firstname.' '.$lastname.' Testimonial&lt;\/a&gt; - Click the link to view this testimonial&lt;br&gt;Written '.$datemade.'&lt;\/p&gt;';\n}\n<\/code><\/pre>\n<p>while statement is essential to know in PHP. It basically keeps executing the code in <code>{ code }<\/code> while the condition in <code>while (condition)<\/code> is true. Important to note that $row is an array (type <code>var_dump($row)<\/code> to see what $row contains). $row here should contain your mysql table entry values. So if your mysql table has a column called post_content, you can output its value using $row[&#8220;post_content&#8221;].<\/p>\n<p>mysqli_close closes the connection to the database.<\/p>\n<p>If there is anything you dont understand let me know<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">13<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Pagination data <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] You need to study their code more, dont just copy&amp;paste. You told the program to echo those variables and it echoed them for you. In the tutorial they seem to store all the &#8216;paginatable&#8217; data in the $list, so you need to look into that. $id = $row[&#8220;id&#8221;]; prints id column from the current &#8230; <a title=\"[Solved] Pagination data\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/\" aria-label=\"More on [Solved] Pagination data\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[346,1117,638,339],"class_list":["post-20473","post","type-post","status-publish","format-standard","hentry","category-solved","tag-html","tag-mysqli","tag-pagination","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Pagination data - JassWeb<\/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:\/\/jassweb.com\/solved\/solved-pagination-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Pagination data - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] You need to study their code more, dont just copy&amp;paste. You told the program to echo those variables and it echoed them for you. In the tutorial they seem to store all the &#8216;paginatable&#8217; data in the $list, so you need to look into that. $id = $row[&quot;id&quot;]; prints id column from the current ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-09T13:59:33+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Pagination data\",\"datePublished\":\"2022-11-09T13:59:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/\"},\"wordCount\":483,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"html\",\"mysqli\",\"pagination\",\"php\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/\",\"name\":\"[Solved] Pagination data - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-11-09T13:59:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pagination-data\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Pagination data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Pagination data - JassWeb","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:\/\/jassweb.com\/solved\/solved-pagination-data\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Pagination data - JassWeb","og_description":"[ad_1] You need to study their code more, dont just copy&amp;paste. You told the program to echo those variables and it echoed them for you. In the tutorial they seem to store all the &#8216;paginatable&#8217; data in the $list, so you need to look into that. $id = $row[\"id\"]; prints id column from the current ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/","og_site_name":"JassWeb","article_published_time":"2022-11-09T13:59:33+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Pagination data","datePublished":"2022-11-09T13:59:33+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/"},"wordCount":483,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["html","mysqli","pagination","php"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/","url":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/","name":"[Solved] Pagination data - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-11-09T13:59:33+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-pagination-data\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-pagination-data\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Pagination data"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/20473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=20473"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/20473\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=20473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=20473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=20473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}