Welcome Guest, Not a member yet? Register   Sign In
Is there a better way to count query results?
#1

[eluser]mhulse[/eluser]
Hi,

In my model, I have this bit of code to check if an entry exists:

Code:
private function check_entry()
{
    $this->db->select('COUNT(*) AS total_count, `container`, `margin`', FALSE);
    $this->db->where('container = ' . $this->container);
    $this->db->where('margin = ' . $this->margin);
    $query = $this->db->get($this->table);
    $result = $query->row();
    return ($result->total_count > 0) ? TRUE : FALSE;
}

And before doing an insert, I call the above method:

Code:
if ( ! $this->check_entry()) {
    $this->db->insert(...);
}

It works, but I am wondering if there is an easier, more efficient, way to make sure an entry is unique before doing an insert?

Sorry if noob question, I am just now learning a bunch of new stuff pertaining to mysql and CI. Big Grin

Thanks!
Micky


Messages In This Thread
Is there a better way to count query results? - by El Forum - 01-23-2010, 10:09 PM
Is there a better way to count query results? - by El Forum - 01-23-2010, 11:27 PM
Is there a better way to count query results? - by El Forum - 01-24-2010, 12:52 AM
Is there a better way to count query results? - by El Forum - 01-24-2010, 01:20 AM
Is there a better way to count query results? - by El Forum - 01-24-2010, 01:22 AM
Is there a better way to count query results? - by El Forum - 01-24-2010, 07:16 AM
Is there a better way to count query results? - by El Forum - 01-24-2010, 03:29 PM
Is there a better way to count query results? - by El Forum - 01-25-2010, 01:23 AM
Is there a better way to count query results? - by El Forum - 01-25-2010, 01:30 AM
Is there a better way to count query results? - by El Forum - 01-25-2010, 01:48 AM
Is there a better way to count query results? - by El Forum - 01-25-2010, 04:48 AM
Is there a better way to count query results? - by El Forum - 01-25-2010, 07:52 AM
Is there a better way to count query results? - by El Forum - 01-25-2010, 11:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB