1

I'm using a select * query from a table.

$query = $this->db->get($table_name);

what I want is to for it to discard all records where the value for a column is empty so for example

Array 
{ 
  Topic_1 -> 
  Topic_2 -> Cats
}

It would discard Topic_1 key and value pair entirely. I'm also using Codeigniter active record so I tried doing

$query = $this->db->get_where($value, array(test_id != 'NULL'));

But i cannot specify each column, I just want test_id to be all columns in the table? Is there someone I can do this or can I just run a loop after the query is returned where it discards unmatched key value pairs?

4

1 回答 1

3

First, you are doing NULL wrong. You should go like this:

$query = $this->db->where('test_id !=', NULL)->get($value)->result_array();

That query will work when field is NULL, but in your case it is not NULL, it is empty. In order for the field to be NULL you must specify it as default when you are creating table. Query for your case would be:

$query = $this->db->where('test_id !=', '')->get($value)->result_array();

For all the fields, I guess you will need to go with foreach loop:

$data = array();
$field = array('field1', 'field2', ...);
foreach($field as $f) :
$query = $this->db->where($f, '')->get('table')->result_array();
$data = $data + $query;
endforeach;

This way in the $data you will get all the field that are empty.

于 2013-05-13T19:03:24.460 回答