I rewrote the code, and this is what I got to work.
function gets($status = NULL, $bought = NULL)
{
// Get the rows where the partner has used clips
$this->db->where('partner_id', $this->session->userdata('partner_id'));
$this->db->where('type', '-');
$query = $this->db->get('clips');
if ($status != FALSE)
{
if(is_array($status))
{
$first = TRUE;
foreach($status as $row)
{
if ($first == TRUE)
{
$this->db->where('leads.status', $row);
$first = FALSE;
}
else
{
$this->db->or_where('leads.status', $row);
}
}
}
else
{
$this->db->where('leads.status', $status);
}
}
$bought_array[] = '';
if ($query->num_rows() != 0)
{
foreach($query->result() as $row2)
{
// Add the ID's of the bought leads to array
$bought_array[] = $row2->lead_id;
}
}
// If bought leads should not be shown in the results
if ($bought == FALSE)
{
$this->db->where_not_in('id', $bought_array);
}
else // If they should...
{
$this->db->where_in('id', $bought_array);
}
$query2 = $this->db->get('leads');
if ($query2->num_rows() != 0)
{
return $query2->result();
}
}