1

I am trying to write a CSV in Codeignter for a result set fetched from db.

I am already using the solution mentioned here. Reports in Codeigniter

But the issue is that it writes the whole table. Now I want to fetch and write specific records. So here is my model code.

    $where = "hangtag_spoc_number = 2202";
    $result = $this->db->select('*')
            ->from('hangtag_request')
            ->where($where)
            ->get()
            ->result_array();
    return $result;

It gives me this error.

You must submit a valid result object

If I change the model code to this

    return $query = $this->db->get('hangtag_request');

It works perfectly. Is there any way I can make my model code to return the results in the form of DB object? Coz it seems thats the form we need.

Thanks.

2 Answers 2

1

If you need result object then you shouldn't use the result_array()

$this->db->get();

The above statement runs the selection query and returns the result.It does return in form that can be used for presentation.

result_array()

This function returns the query result as an array, or an empty array when no result is produced.

Its good to use return $query = $this->db->get('hangtag_request'); for obtaining result object.

Sign up to request clarification or add additional context in comments.

Comments

1

I got it solved.

Just had to remove result_array() so the correct code becomes

$where = "hangtag_spoc_number = 2202";
$result = $this->db->select('*')
        ->from('hangtag_request')
        ->where($where)
        ->get();
return $result;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.