Welcome Guest, Not a member yet? Register   Sign In
Insert Current Date
#1

[eluser]harpster[/eluser]
Just learning CI and getting used to the MVC concept with the on-line videos and examples in the CI User Guide. I'm not sure about this part so I'm going to show what I did that worked and ask for how others would do the same thing. Very simply I need to insert the current date with my posted form data. I suppose I could have done this with a hidden field in the view to include that in the POST array. Doing it in the model after the fact seems to take more code as shown below. Is there a way to simplify this or is it better to use a hidden field in the view for the date? Thanks!


Code:
function add_record()
    {
        $this->db->insert('cycling', $_data);
        
        //Add CURRENT DATE to Record
        $id=$this->db->insert_id();  //get id of last record
        $this->db->where('id', $id);
        $data = array('ridedate' => date('Y-m-d'));
        $this->db->update('cycling', $data);
        return;
    }


Messages In This Thread
Insert Current Date - by El Forum - 02-13-2011, 09:03 AM
Insert Current Date - by El Forum - 02-13-2011, 09:19 AM
Insert Current Date - by El Forum - 02-13-2011, 09:56 AM
Insert Current Date - by El Forum - 02-13-2011, 12:16 PM
Insert Current Date - by El Forum - 02-13-2011, 12:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB