Welcome Guest, Not a member yet? Register   Sign In
advanced database query :p
#1

[eluser]johansonevR[/eluser]
hello,
i am new to this forum as i am new to CI. However i am looking at the blog tutorial.
well the problem is here i don't know how to explain it exactly but i will give it a try.
i have a function:
user clicks on a link and gets the data from view().
Code:
function view(){
        $data['contents']=$this->db->get('adv');
        $this->load->view("adv_view_view",$data);
    }
the problem is that this function does not know which table row to select, it selects them all. How to select the id of the table i want to use dynamically, i want my db query to become
Code:
$this->db->query("select * from adv where id='$id';");
i want to get the the variable $id from the previous page and use it in the query.
#2

[eluser]theprodigy[/eluser]
Quote:$this->db->query("select * from adv where id='$id';");
What you are looking for is:
Code:
$this->db->where('id',$id);
$this->db->get('adv');
You can read all about CodeIgniter's Active Record implementation here
#3

[eluser]johansonevR[/eluser]
tnx for the reply , however i still don't understand how to get the id from this :
Code:
anchor("adv/view/".$row->id, "View");
#4

[eluser]theprodigy[/eluser]
Quote:function view(){
$data['contents']=$this->db->get('adv');
$this->load->view("adv_view_view",$data);
}
Quote:anchor("adv/view/".$row->id, "View");

I'm going to assume that this function is in a Controller called adv.

What you need to do is give your view method a parameter, and use that parameter.
Code:
function view($id){
    $this->db->where('id',$id);
    $data['contents']=$this->db->get('adv');
    $this->load->view("adv_view_view",$data);
}
#5

[eluser]johansonevR[/eluser]
tnx




Theme © iAndrew 2016 - Forum software by © MyBB