Welcome Guest, Not a member yet? Register   Sign In
DB Query returning all results instead of single
#1

[eluser]mflammia[/eluser]
Been scracthing my head over this one for a while but I just can't seem to explain the results.

I have the following entry in my controller

Code:
function get_records_edit(){
                $this->load->model('site_model');
                $this->site_model->get_single_record();
                $data = $this->results();
                echo "<pre>";
                echo print_r($data);
                echo "<pre>";

And the following entry in my model

Code:
function get_single_record(){
            $query = $this->db->query('SELECT * FROM person WHERE id_person='.$this-&gt;uri-&gt;segment(3));
            echo "&lt;pre&gt;";
            echo print_r($query);
            echo "&lt;pre&gt;";

I should get returned a sinlge entry the model echo returns:

Code:
CI_DB_mysql_result Object
(
    [conn_id] =&gt; Resource id #29
    [result_id] =&gt; Resource id #32
    [result_array] =&gt; Array
        (
        )

    [result_object] =&gt; Array
        (
        )

    [custom_result_object] =&gt; Array
        (
        )

    [current_row] =&gt; 0
    [num_rows] =&gt; 1
    [row_data] =&gt;
)
1

But the controller echo returns an array of all the entries in the id_person table instead of a single entry?

Ive taken the entry

Code:
SELECT * FROM person WHERE id_person='.$this->uri->segment(3)

Saved it to a varible and echo'd it out and it does work properly in translating to something like

Code:
SELECT * FROM person WHERE id_person=7

Help much appreciated in advance.
#2

[eluser]mflammia[/eluser]
Silly me :-)

Just realised I have called a local function within my contorller

Code:
$data = $this->results();

instead of calling the correct one in my model.

Sorry for wasting anyones time.




Theme © iAndrew 2016 - Forum software by © MyBB