<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	class Mod_car extends CI_Model
	{
		var $table = "tblcar";
		function __construct()
		{
			parent::__construct();
		}	
		
		function getcar ($c=1,$id="")
		{
			//$this->db->SELECT("*");
			//$this->db->from("tblcar");
			//$this->db->join("tbluser","tbluser.userid = tblcar.createby","left");
			//return $this->db->get();
			$sql = "select a.*,(select tbltypecar.typename from tbltypecar where a.cartype = tbltypecar.id) as typename, (select b.name from tblbrand as b where a.brandname = b.id) as brandname,(SELECT c.username from tbluser as c where a.createby=c.userid)as username from tblcar as a";
			
			return $this->db->query($sql);
			
		}
		
		 
		function countAll()
		{
			return $this->db->count_all_results('tblcar');
		}
		
			
		function add($data)
		{
			$this->db->insert($this->table,$data);
			
		}


		function update($data,$id)
		{
			$this->db->where("id",$id);
			$this->db->update($this->table,$data);
		}
		

		function delete($id)
		{
			$this->db->where("id",$id);
			$this->db->delete($this->table);
		}
		
	
		function getById($id)
		{
			$this->db->where("id",$id);
			$q = $this->db->get($this->table);
			if($q->num_rows() > 0)
			{
				return $q->row();
			}
			return false;
		}
		
			
		
		
	}