Welcome Guest, Not a member yet? Register   Sign In
Get results from model to controler and show in view
#5

[eluser]Edemilson Lima[/eluser]
[quote author="erikv4" date="1198301274"]Try running var_dump($result);

You'll see that even though the database returned just one item (your count), $result is a little bit more complicated. The fact that you only needed one field from one row means that $query->row() is probably what you want instead of $query->result()[/quote]

If you use GROUP BY in your query, the database will return one row for the total of each group. In this case, it is necessary to fetch all the rows and sum the subtotals to get the the real total rows returned by the query. Example:

Code:
$records=mysql_num_rows($result);
if($records==1) { // no groups where used
  $row=mysql_fetch_array($result);
  $num_rows=intval($row[0]);
  return $num_rows;
} elseif($records>1) { // query with group
  $total_rows=0;
  while($row=mysql_fetch_array($result)) {
    $total_rows+=intval($row[0]);
  }
  return $total_rows;
}


Messages In This Thread
Get results from model to controler and show in view - by El Forum - 12-21-2007, 04:50 PM
Get results from model to controler and show in view - by El Forum - 12-21-2007, 05:27 PM
Get results from model to controler and show in view - by El Forum - 12-22-2007, 07:21 PM
Get results from model to controler and show in view - by El Forum - 12-22-2007, 08:49 PM
Get results from model to controler and show in view - by El Forum - 12-27-2007, 11:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB