Welcome Guest, Not a member yet? Register   Sign In
Can I return lots of results from one model function?
#1

[eluser]Assim[/eluser]
I know how I can return one function from a model, and I know I can do the same if I want to return another thing, but to save queries, I want to return lots of things with one function.

To be clear, let's say I want to get the title and page contents from the database. They both are in the same table, but with the model I know how to get them in two different functions, is there a way to get them in one model function and give them each a variable?
#2

[eluser]imn.codeartist[/eluser]
just store everything into array and return the array
#3

[eluser]Assim[/eluser]
Can I please have a simple demonstration of that?
#4

[eluser]überfuzz[/eluser]
Code:
$array = array('first_value','second_value');
return $array;
#5

[eluser]Assim[/eluser]
Thanks a million. Smile
#6

[eluser]überfuzz[/eluser]
You're welcome! My first thought was, what a lazy dude, won't even look in the manual, but then I saw that you're new here. Welcome to this forum! :-)
#7

[eluser]überfuzz[/eluser]
By the way. When you've get a hang of how to return stuff have a look at the user_guide. It covers how to query and return arrays.
#8

[eluser]Assim[/eluser]
Thanks. Smile

Yeah, I'm kinda new in this MVC thing. Wink
#9

[eluser]Assim[/eluser]
I still don't know how to use the active record in the models.

I know everything that is needed to be known about the models, but let's say I want to perform the following query:
SELECT name, password, email FROM users WHERE id = '1';

How can I perform it?

This is some of the code where I just wrote it:
Code:
function get_user()
    {
    $query = $this->db->get('users');
        return $query->result();
    }

But I don't know how to do what I asked above.
#10

[eluser]n0xie[/eluser]
Code:
$sql = "SELECT name, password, email FROM mytable WHERE id = 1";
$query = $this->db->query($sql);
if ($query->num_rows() > 0)
{
    // return the results as an object
    return $query->result();
    // or as an array
    return $query->result_array();
{
else
{
    // no result was found or an error occurred
    return FALSE;
}




Theme © iAndrew 2016 - Forum software by © MyBB