Revision: 64567
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 23, 2013 19:59 by brownrl
Initial Code
<snippet> <content><![CDATA[ \$offset = 0; \$page = 1; \$pp = 6; \$table = "users"; \$field = "user_created_timestamp"; \$dir = "DESC"; if( isset( \$_GET['p'] ) ) { \$page = intval( \$_GET['p'] ); \$offset = ( \$page - 1 ) * \$pp; } // get the total \$q = "SELECT COUNT( * ) AS total FROM \$table"; \$qr = dbQuery( \$q ); \$qrow = dbFetchArray( \$qr ); \$total = \$qrow['total']; // Do the real select \$q = "SELECT * FROM ".\$table." ORDER BY ".\$field." ".\$dir." LIMIT ".\$pp." OFFSET ".\$offset; \$qr = dbQuery( \$q ); \$assigns['total'] = \$total; \$totalpages = ceil( \$total / \$pp ); \$assigns['totalpages'] = \$totalpages; \$assigns['items'] = dbFetchAllArray( \$qr ); \$prev = false; \$first = false; \$next = true; \$last = true; if( \$offset != 0 ) { \$prev = true; \$first = true; } if( \$page == \$totalpages ) { \$next = false; \$last = false; } \$assigns['prevpage'] = \$page - 1; \$assigns['nextpage'] = \$page + 1; \$assigns['first'] = \$first; \$assigns['prev'] = \$prev; \$assigns['next'] = \$next; \$assigns['last'] = \$last; ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>pageit</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- <scope>source.python</scope> --> </snippet>
Initial URL
http://www.itsgotto.be/cv.php
Initial Description
This is a quick sublime snippet to quickly setup a DB table for pagination. Ideally from here you will be into a smarty template.
Initial Title
Sublime Snippet: pageit
Initial Tags
php
Initial Language
PHP