Welcome Guest, Not a member yet? Register   Sign In
return num_rows and query results
#6

[eluser]TheFuzzy0ne[/eluser]
[quote author="Samuurai" date="1243637809"]Thanks for that...[/quote]

You're welcome...

[quote author="Samuurai" date="1243637809"]I'm a bit confused though... why can't I just count the array somehow at the PHP level, like the standard mysql_num_rows..?[/quote]

Scalability. If you have 10,000 rows in your database, you don't want to get all 10,000 rows, do you? If the table is going to be small, and stay small, and you know this for a fact, then yes, you can count the results, but that's what num_rows() is for.

[quote author="Samuurai" date="1243637809"]I'm happy to just use the PHP functions rather than AR.. I think this will have to be done in the controller though..unless it's possible for a function in the model to return two values, one for the array containing the results and one for the number of rows..?[/quote]

You can only return a single result, but there's nothing stopping you returning whatever you want in an object or an array.
Code:
return array(
        'total_rows' => $total_rows,
        'results' => $res->result_array()
    );


Messages In This Thread
return num_rows and query results - by El Forum - 05-29-2009, 11:10 AM
return num_rows and query results - by El Forum - 05-29-2009, 11:18 AM
return num_rows and query results - by El Forum - 05-29-2009, 11:30 AM
return num_rows and query results - by El Forum - 05-29-2009, 11:40 AM
return num_rows and query results - by El Forum - 05-29-2009, 11:56 AM
return num_rows and query results - by El Forum - 05-29-2009, 12:06 PM
return num_rows and query results - by El Forum - 05-29-2009, 12:09 PM
return num_rows and query results - by El Forum - 05-29-2009, 12:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB