Created
October 16, 2012 16:56
-
-
Save tony1223/3900544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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