Skip to content

Instantly share code, notes, and snippets.

@tony1223
Created October 16, 2012 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony1223/3900544 to your computer and use it in GitHub Desktop.
Save tony1223/3900544 to your computer and use it in GitHub Desktop.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ArticleModel extends CI_Model {
function __construct()
{
parent::__construct();
}
function insert($author,$title,$content){
$this->db->insert("article",
Array(
"Author" => $author,
"Title" => $title,
"Content" => $content,
"Views" => 0,
));
return $this->db->insert_id() ;
}
function get($articleID){
$this->db->select("article.*,user.Account");
$this->db->from('article');
$this->db->join('user', 'article.author = user.userID', 'left');
$this->db->where(Array("articleID" => $articleID));
$query = $this->db->get();
if ($query->num_rows() <= 0){
return null; //無資料時回傳 null
}
return $query->row(); //回傳第一筆
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment