np_model.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. class np_model extends Model
  3. {
  4. var $langid = "zh";
  5. function __construct()
  6. {
  7. parent::Model();
  8. }
  9. function np_model()
  10. {
  11. $this->__construct();
  12. }
  13. function langid($langid="zh")
  14. {
  15. $this->langid = $langid;
  16. }
  17. function get_mid($id)
  18. {
  19. $sql = "SELECT module_id FROM ".$this->db->prefix."list WHERE id='".$id."'";
  20. $rs = $this->db->get_one($sql);
  21. return $rs["module_id"];
  22. }
  23. //取得下一主题
  24. function get_next($id,$cateid=0,$pictype="",$num=1)
  25. {
  26. if(!$cateid)
  27. {
  28. $mid = $this->get_mid($id);
  29. }
  30. if(!$cateid && !$mid)
  31. {
  32. return false;
  33. }
  34. if($pictype)
  35. {
  36. $sql = "SELECT l.*,u.filename picture FROM ";
  37. }
  38. else
  39. {
  40. $sql = "SELECT l.* FROM ";
  41. $pictype = "thumb";
  42. }
  43. $sql.= " ".$this->db->prefix."list l LEFT JOIN ".$this->db->prefix."upfiles_gd u ON (l.thumb_id=u.pid AND u.gdtype='".$pictype."') ";
  44. $sql.= " WHERE l.id>'".$id."' AND l.langid='".$this->langid."' AND l.status='1' AND l.hidden='0' ";
  45. if($cateid)
  46. {
  47. $sql.= " AND l.cate_id='".$cateid."'";
  48. }
  49. else
  50. {
  51. $sql.= " AND l.module_id='".$mid."'";
  52. }
  53. $sql.= " ORDER BY l.post_date DESC,l.id DESC LIMIT ".$num;
  54. return $this->db->get_all($sql);
  55. }
  56. //取得上一主题
  57. function get_prev($id,$cateid=0,$pictype="",$num=1)
  58. {
  59. if(!$cateid)
  60. {
  61. $mid = $this->get_mid($id);
  62. }
  63. if(!$cateid && !$mid)
  64. {
  65. return false;
  66. }
  67. if($pictype)
  68. {
  69. $sql = "SELECT l.*,u.filename picture FROM ";
  70. }
  71. else
  72. {
  73. $sql = "SELECT l.* FROM ";
  74. $pictype = "thumb";
  75. }
  76. $sql.= " ".$this->db->prefix."list l LEFT JOIN ".$this->db->prefix."upfiles_gd u ON (l.thumb_id=u.pid AND u.gdtype='".$pictype."') ";
  77. $sql.= " WHERE l.id<'".$id."' AND l.langid='".$this->langid."' AND l.status='1' AND l.hidden='0' ";
  78. if($cateid)
  79. {
  80. $sql.= " AND l.cate_id='".$cateid."'";
  81. }
  82. else
  83. {
  84. $sql.= " AND l.module_id='".$mid."'";
  85. }
  86. $sql.= " ORDER BY l.post_date DESC,l.id DESC LIMIT ".$num;
  87. return $this->db->get_all($sql);
  88. }
  89. }
  90. ?>