/ Published in: PHP
                    
                                        
This is a quick sublime snippet to quickly setup a DB table for pagination. Ideally from here you will be into a smarty template.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<snippet>
<content><![CDATA[
\$offset = 0;
\$page = 1;
\$pp = 6;
\$table = "users";
\$field = "user_created_timestamp";
\$dir = "DESC";
\$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;
\$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>
<tabTrigger>pageit</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
URL: http://www.itsgotto.be/cv.php
Comments
 Subscribe to comments
                    Subscribe to comments
                
                