Welcome Guest, Not a member yet? Register   Sign In
Active Record or SQL Question
#1

[eluser]bennyhill[/eluser]
Currently I am inserting multiple records at once with this code:

Code:
$data = array();
        foreach ($_POST['tableGuests'] as $key => $value)
        {
            $temp = '('.$value.','.$_POST['owner_id'].')';
            array_push($data, $temp);
        }
        
       $values = implode(",",array_values($data));
       $sql = "INSERT INTO `table` (`attendee_id`, `owner_id`) VALUES ".$values;
       $this->db->query($sql);

Is there a better, more simple way to do it with Active Record?
#2

[eluser]GSV Sleeper Service[/eluser]
I'm not sure if you can even do multiple inserts using Active Record, the docs don't mention anything about it.
I do like your implode method though, I can't believe I never thought of that before. I always used to do something like
Code:
$sep = "";
$sql = "";
foreach($thing as $k => $v){
    $sql.= $sep."('".$k."','".$v."')";
    $sep = ",";
}




Theme © iAndrew 2016 - Forum software by © MyBB