|
![](/images/resource/spacer.gif) |
|
สอบถามผู้รู้ ต้องการเขียน function serach ใน CI Framework แบบ php activerecord โดยสามารถเลือก serach ได้ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ปกติเขียนยังไงครับ?
ลองเขียนไปแล้วบ้างหรือยัง?
จะเขียนใน controller หรือใน model->method ก็ได้ขึ้นอยู่กับสะดวกแบบไหน
แต่จะให้ดีก็เขียนใน model
ลองดูคู่มือของ CI อะครับเกี่ยวกับ like() where()
|
ประวัติการแก้ไข 2015-02-11 18:36:40
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-02-11 18:35:32 |
By :
mr.v |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ประมาณนี้เปล่าครับ
Controller
Code (PHP)
<?php
public function serach()
{
$c_id = $this->input->post('Citizend_ID');
$f_name = $this->input->post('Firstname');
$l_name = $this->input->post('Lastname');
if($this->model->serach($c_id,$f_name,$l_name))
{
//next step
}
}
?>
Model
Code (PHP)
<?php
public function serach($c_id,$f_name,$l_name)
{
if($c_id !="" || $f_name !="" || $l_name !="")
{
$this->db->select('bla,bla,bla');
if($c_id != "")
{
$this->db->like('column',$c_id);
}
if($f_name != "")
{
$this->db->like('column',$f_name);
}
if($l_name != "")
{
$this->db->like('column',$l_name);
}
return $this->db->get()->result();
}else
{
//select all
}
}
?>
|
ประวัติการแก้ไข 2015-02-12 10:44:23 2015-02-12 10:46:05
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-02-12 10:42:37 |
By :
tam78910 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ประมาณนั้นเลยครับ มาถูกทางแล้ว ![](/images/bbcode/smile.gif?v=1001)
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-02-19 00:31:19 |
By :
mr.v |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 04
|