Group: http://groups.google.com/group/codeigniter-kenya/topics
Isaak Mogetutu <imog...@gmail.com> Aug 02 12:34AM -0700
I'm eeked out by this code segment:
if ($result == FALSE) {
return FALSE;
}
if ($result->num_rows() == 0) {
return FALSE;
}
Quick question if $result == false can $result->num_rows() != 0 thats why
the double checks for false
Instead can you check if its true load master array else return false
// Not tested just my thoughts
function count_distinct_values($table_name = '', $column_name = '')
{
$result = $this->db->query("SELECT $column_name, count(*) AS
value_count FROM $table_name GROUP BY $column_name");
if ($result) {
$master_array = array();
foreach ($result->result_array() as $row) {
$master_array[$row[$column_name]] = $row['value_count'];
}
return $master_array;
}
return FALSE;
}
On Thursday, 1 August 2013 16:49:14 UTC+3, Peter Karunyu wrote:
Peter Karunyu <pkar...@gmail.com> Aug 02 10:39AM +0300
--
I got into the habit of separating num_rows() from the other one coz I
sometimes need to differentiate from a query failing (which is super bad)
to a query not returning any data (which is ok).
But in the example above, there's no need for that so yes, your suggestion
is better
--
Regards,
Peter Karunyu
-------------------
You received this message because you are subscribed to the Google Groups "CodeIgniter Kenya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codeigniter-ke...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.