Welcome Guest, Not a member yet? Register   Sign In
Is there no longer a need for num_rows()?
#4

(08-12-2019, 02:54 AM)tgix Wrote:
(08-12-2019, 02:17 AM)daveĀ friend Wrote: I think you're looking for $builder->countAllResults()

Yeah, but that queries the database again, which num_rows() in CI3 doesn't do. I guess I'll do the count() once and then keep the result as a variable.

Digging deeper I see that BaseResult has a public property - $numRows. It appears that by using any db operation that returns a Result you should be able to do something like this.

PHP Code:
$res $db->query("YOUR QUERY")->getResult();
$count $res->numRows

I haven't confirmed my premise, only explored the source code. However, after exploring the source more deeply I'm skeptical about my correctness. I cannot find any place where $numRows is assigned a value. (I"m looking at the current state of the develop branch - last commit on Aug 11, 2019)

Even if I'm wrong that property might be a useful place to store the result of your count() call.
Reply


Messages In This Thread
RE: Is there no longer a need for num_rows()? - by dave friend - 08-12-2019, 09:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB