model_main.php 663 B

1234567891011121314151617181920212223
  1. <?php
  2. class Model_main extends Model
  3. {
  4. public function get_posts(){
  5. $q = "SELECT * FROM `posts` ORDER BY `updated_at` DESC";
  6. return $this->db->query($q);
  7. }
  8. public function get_post($id){
  9. $q = "SELECT * FROM `posts` WHERE `id` = " . $this->db->escape($id);
  10. return $this->db->query($q);
  11. }
  12. public function create_post($caption, $post){
  13. $q = "INSERT INTO `posts` SET `caption` = " . $this->db->escape($caption) .
  14. ", `post` = " . $this->db->escape($post) .
  15. ", `user_id` = " . $this->db->escape($_SESSION['user']['id']);
  16. $this->db->query($q);
  17. }
  18. }