Welcome Guest, Not a member yet? Register   Sign In
newbie could use some quick help to get started
#1

[eluser]Unknown[/eluser]
Hi,
just started using codeigniter so bare with me. It seems very easy to use but i need some help understanding something.

if i am passing parameters like:
http://domain.com/company/view/210

where 210 is my parameter, how would i code so that i could pull that record from the database? here is what i have so far:

in the controller company.php

Code:
public function view($id)
    {

        $this->load->model('Company_model');
        $this->load->view('templates/header');
        $data['result'] = $this->Company_model->view();
        $this->load->view('company/view', $data);
        $this->load->view('templates/footer');

    }

and in the model company_model.php

Code:
public function view($id)
    {

             $query = $this->db->query("SELECT * FROM `company`  WHERE `id` =  $id");
             return $query->result();
    }

im sure my model is not correct, ive been trying a few things from the guide but cant seem to get it.

thanks for any help!

#2

[eluser]jairoh_[/eluser]
in
Code:
$data['result'] = $this->Company_model->view();

just reference the $id

Code:
$data['result'] = $this->Company_model->view($id);
#3

[eluser]Unknown[/eluser]
Thanks for that info, is there a guide that talks about using parameters with sql queries? i could'nt find anything.

I added the view($id); but when outputting that to a page using

<?php echo $data('id'); ?>

im getting: Message: Undefined variable: data
#4

[eluser]jairoh_[/eluser]
i can't find guides but it takes a lot of experience. but if you pass it in a view

ex.

Code:
$data [ 'id' ] = 12312;

$this->load->view( 'my_view', $data );

in my_view, just echo id

Code:
echo $id;




Theme © iAndrew 2016 - Forum software by © MyBB