Note that there are some explanatory texts on larger screens.

plurals
  1. PODigg Style pagination Class
    text
    copied!<p>I am new to PHP and have been trying to build my first project these last few days, it's working mostly as a blog - just so I get a feeling on how to query a database and whatnot.</p> <p>I now want to be able to paginate the results on my page, this is what I have so far:</p> <pre><code>&lt;?php include_once 'inc/functions.inc.php'; include_once 'inc/db.inc.php'; $db = new PDO(DB_INFO, DB_USER, DB_PASS); $id = (isset($_GET["id"])) ? (int) $_GET["id"] : NULL; $e = retrievePosts($db, $id); $fulldisp = array_pop($e); ?&gt; &lt;div id="blogposts"&gt; &lt;?php if ($fulldisp == 1) { ?&gt; &lt;span class="postdate"&gt;&lt;?php echo $e["date"] ?&gt;&lt;/span&gt; &lt;span class="posttitle"&gt;&lt;?php echo $e["title"] ?&gt;&lt;/span&gt; &lt;br/&gt; &lt;br/&gt; &lt;span class="postbody"&gt; &lt;?php echo $e["body"] ?&gt; &lt;/span&gt; &lt;?php }//end if else { foreach ($e as $entry) { ?&gt; &lt;div class="postholder"&gt; &lt;span class="postdate"&gt;&lt;?php echo $entry["date"] ?&gt;&lt;/span&gt; &lt;span class="posttitle"&gt; &lt;a href="?id=&lt;?php echo $entry['id'] ?&gt;"&gt;&lt;?php echo $entry['title'] ?&gt;&lt;/a&gt; &lt;/span&gt; &lt;br/&gt; &lt;br/&gt; &lt;span class="postbody"&gt; &lt;?php echo $entry["resume"] ?&gt; &lt;/span&gt; &lt;/div&gt; &lt;?php }//end foreach }//end ?&gt; &lt;/div&gt; </code></pre> <p>And this my function:</p> <pre><code>&lt;?php function retrievePosts($db, $id = NULL) { if (isset($id)) { //se foi fornecido ID $sql = "SELECT title, body, date FROM blog WHERE id=? LIMIT 1"; $stmt = $db-&gt;prepare($sql); $stmt-&gt;execute(array($_GET["id"])); $e = $stmt-&gt;fetch(); //guardar em array $fulldisp = 1; //uma só entrada } else { $sql = "SELECT id, title, resume, date FROM blog ORDER BY date DESC"; foreach($db-&gt;query($sql) as $row) { $e[] = array("id" =&gt; $row["id"], "title" =&gt; $row["title"], "resume" =&gt; $row["resume"], "date" =&gt; $row["date"]); } $fulldisp = 0; //multiplas entradas } //funçoes só retornam um valor, inserimos fulldisp no fim de $e e separamos //os valores de novo no index.php array_push($e, $fulldisp); return $e; } ?&gt; </code></pre> <p>The way this works is, the page is built depending on the URL:</p> <p>If there is an id there, it displays the content of only that ID. </p> <p>If there isn't an id in the URL, it is now displaying all the entries in the page.</p> <p>I now want to be able to paginate these entries, so after having a look around Stackoverflow, it seems the most popular solution is to use the <strong>Digg Style Pagination Class</strong>, documented here: <a href="http://mis-algoritmos.com/digg-style-pagination-class" rel="nofollow">http://mis-algoritmos.com/digg-style-pagination-class</a></p> <p>I've downloaded the class, but I can't figure out how to get this working properly, I'm confused by the fact that the class doesn't have a DB query (I'd expect this to use LIMIT), I was wondering if anyone here on Stack could help me implement this class on my code, or if there is a well documented source on how to do this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload