崇高片段:pageit

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了崇高片段:pageit相关的知识,希望对你有一定的参考价值。

This is a quick sublime snippet to quickly setup a DB table for pagination. Ideally from here you will be into a smarty template.
  1. <snippet>
  2. <content><![CDATA[
  3.  
  4. $offset = 0;
  5. $page = 1;
  6. $pp = 6;
  7. $table = "users";
  8. $field = "user_created_timestamp";
  9. $dir = "DESC";
  10.  
  11. if( isset( $_GET['p'] ) ) {
  12. $page = intval( $_GET['p'] );
  13. $offset = ( $page - 1 ) * $pp;
  14. }
  15.  
  16. // get the total
  17. $q = "SELECT COUNT( * ) AS total FROM $table";
  18. $qr = dbQuery( $q );
  19. $qrow = dbFetchArray( $qr );
  20. $total = $qrow['total'];
  21.  
  22.  
  23. // Do the real select
  24. $q = "SELECT * FROM ".$table." ORDER BY ".$field." ".$dir." LIMIT ".$pp." OFFSET ".$offset;
  25. $qr = dbQuery( $q );
  26.  
  27. $assigns['total'] = $total;
  28. $totalpages = ceil( $total / $pp );
  29. $assigns['totalpages'] = $totalpages;
  30. $assigns['items'] = dbFetchAllArray( $qr );
  31.  
  32. $prev = false;
  33. $first = false;
  34. $next = true;
  35. $last = true;
  36.  
  37. if( $offset != 0 ) {
  38. $prev = true;
  39. $first = true;
  40. }
  41.  
  42. if( $page == $totalpages ) {
  43. $next = false;
  44. $last = false;
  45. }
  46.  
  47. $assigns['prevpage'] = $page - 1;
  48. $assigns['nextpage'] = $page + 1;
  49. $assigns['first'] = $first;
  50. $assigns['prev'] = $prev;
  51. $assigns['next'] = $next;
  52. $assigns['last'] = $last;
  53.  
  54.  
  55.  
  56. ]]></content>
  57. <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
  58. <tabTrigger>pageit</tabTrigger>
  59. <!-- Optional: Set a scope to limit where the snippet will trigger -->
  60. <!-- <scope>source.python</scope> -->
  61. </snippet>

以上是关于崇高片段:pageit的主要内容,如果未能解决你的问题,请参考以下文章

xml 崇高的片段

xml 崇高的片段

崇高片段:消亡

崇高片段:Fic

崇高片段:fuc

微信小程序代码片段