Can ActiveRecord do this?

18 views
Skip to first unread message

Peter Karunyu

unread,
May 2, 2012, 9:11:46 AM5/2/12
to codeigni...@googlegroups.com
Good people,
I want to copy rows from a table that meet certain conditions, then re-insert them back into the same table after modifying some data, sort of, as has been explained here. I know I can select the said data using a normal select, loop through the results, generate an insert in the loop and insert, but I don't want to do that...

Now, using plain SQL, that would be something like:
INSERT INTO table (col1, col2, col3, ...)
SELECT col1, col2, col3, ... FROM table WHERE primarykey = $something

Question: How do you achieve the same using CI ActiveRecord?



Felix mwai

unread,
May 2, 2012, 9:21:52 AM5/2/12
to codeigni...@googlegroups.com
I had the same problem several days ago but ended up doing this
........................
$sql="
        INSERT INTO tbl_deletedbatches (batchID,yearID,transactionID,date,
        chequeID,userID,file,status)
        SELECT batchID,    yearID,transactionID,date,
        chequeID,userID,file,status
        FROM tbl_batches WHERE tbl_batches.batchID='".$batchid."'";
        $sql=$this->db->query($sql);
............................

I hope somebody on the list has the solution for active record because i ended up ignoring it for this particular case
--
Regards
Felix Mwai
Software Developer.
Mobile 0720453684.

Peter Karunyu

unread,
May 4, 2012, 2:24:16 AM5/4/12
to codeigni...@googlegroups.com
I too had to use the long way, SELECT the data, loop through it and generate an INSERT since I had to use ActiveRecord.
Reply all
Reply to author
Forward
0 new messages