<?php
class Province extends CI_Controller {
var $province_id;
public function __construct()
{
parent::__construct();
// Your own constructor code
$this->load->model('Province_model');
$this->load->helper('url');
}
function form()
{
$data['province']= $this->Province_model->get_province();
$data['amphur']= $this->Province_model->get_amphur();
$data['district']= $this->Province_model->get_district();
$this->load->view('province', $data);
}
function amphur()
{
//echo $this->input->post('id');
$data['amphur']=$this->Province_model->get_amphur();
$this->load->view('province', $data);
}
}
?>
model ครับ Code (PHP)
<?php
class Province_model extends CI_Model {
var $id;
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_province()
{
$query = $this->db->get('province');
return $query->result_array();
}
function get_amphur()
{
$this->db->from('amphur');
$this->db->where('PROVINCE_ID',$this->input->post('provinceid'));
$query =$this->db->get();
return $query->result_array();
}
}
?>
function get_amphur($porvinceid)
{
$this->db->from('amphur');
$this->db->where('PROVINCE_ID',$this->provinceid);
$query =$this->db->get();
return $query->result_array();
}
controller Code (PHP)
function amphur($provinceid)
{
//เรียกใช้ model
$data['amphur']=$this->Province_model->get_amphur($this->input->post('provinceid'));
$this->load->view('province', $data);
}
Date :
2014-02-05 12:06:25
By :
narubet
No. 3
Guest
ใน model จาก Code (PHP)
function get_amphur($porvinceid)
{
$this->db->from('amphur');
$this->db->where('PROVINCE_ID',$this->provinceid);
$query =$this->db->get();
return $query->result_array();
}
เป็น
Code (PHP)
function get_amphur($porvinceid)
{
$this->db->from('amphur');
$this->db->where('PROVINCE_ID',$porvinceid);
$query =$this->db->get();
return $query->result_array();
}
<?php
class Province extends CI_Controller {
var $province_id;
public function __construct()
{
parent::__construct();
// Your own constructor code
$this->load->model('Province_model');
$this->load->helper('url');
}
function form()
{
$data['province']= $this->Province_model->get_province();
$this->load->view('province', $data);
}
function amphur($provinceid)
{
$data['amphur']=$this->Province_model->get_amphur($this->input->post('provinceid'));
$this->load->view('province', $data);
}
}
?>
model
Code (PHP)
<?php
class Province_model extends CI_Model {
var $provinceid;
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_province()
{
$query = $this->db->get('province');
return $query->result_array();
}
function get_amphur($porvinceid)
{
$this->db->from('amphur');
$this->db->where('PROVINCE_ID',$provinceid);
$query =$this->db->get();
return $query->result_array();
}
function get_district($amphurid)
{
$this->db->from('district');
$this->db->where('AMPHUR_ID',$amphurid);
$query =$this->db->get();
return $query->result_array();
}
}
?>