Multiple result set, filter data

edited November 2011 in Modules
what is the best way to filter data which is already on my database.
I have data on database and called it by
$this->find_all_assoc();
which gives result:
array
1 =>
object(stdClass)[41]
public 'id' => string '1' (length=1)
public 'class_id' => string '25' (length=2)
public 'section_id' => string '2' (length=1)
public 'student_id' => string '1' (length=1)
public 'date' => string '2011-11-27' (length=10)
public 'attendance' => string 'present' (length=7)
My new data from $_POST IS:

array
0 =>
array
'class_id' => string '25' (length=2)
'section_id' => string '2' (length=1)
'student_id' => int 1
'date' => string '2011-11-27 00:00:00' (length=19)
'attendance' => string 'present' (length=7)
1 =>
array
'class_id' => string '25' (length=2)
'section_id' => string '2' (length=1)
'student_id' => int 2
'date' => string '2011-11-27 00:00:00' (length=19)
'attendance' => string 'present' (length=7)
On this both data one is duplicate.
can you suggest me the fuel cms way to filder and add data without duplicate.

To insert I am using
$this->db->insert_batch('table_name', $data);

Comments

  • edited 11:18AM
    I'm sorry but I'm not quite sure I understand so a couple of questions:

    1. Where is the $_POST coming from?
    2. Where is $data coming from with your insert_batch statement

    As an FYI, find_all_assoc will give you an array result set with the key values being the 'id' value in the example provided.
  • edited 11:18AM
    $_POST is $data, I have retrived data from a form and processed on controller so that it is on the format column = array key, value = array values.

    on codeigniter there is a method which inserts such data with insert_batch.

    now I only need to do is the data which is on database retrieved with find_all_assoc(), should not be inserted again.
  • edited 11:18AM
    If you use the model's "save()" method, and the saving data has the appropriate key values provided, then it will do an update, otherwise it will do an insert. So in your case, you may try something like:
    $this->my_model->save($_POST);
    However, for those values that are not new and you are essentially updating, you should include the records "id" value as well.
Sign In or Register to comment.