将数组插入数据库codeigniter

时间:2012-10-29 04:02:46

标签: sql arrays codeigniter

我试图在CI中创建sql代码,问题是t_publisher中的ID_LABEL填充为0,其中应填充从t_label获取的数字..

$sql['query1'] = "INSERT into t_user (USER_NAME, USER_PASS, USER_STATUS, USER_TYPE) values ('$user', '$pass','1','publisher')";
$sql['query2'] = "INSERT INTO t_label (LABEL) values('$user')";
$id_label = "select id_label from t_label where label ='".$user."'";
$id = $this->db->query($id_label)->result();
$sql['query3'] = "INSERT INTO t_publisher (PUBLISHER, ARTIS, ID_LABEL) values('$user', 'Various Artist', '$id')";
$result = array();
foreach($sql as $key => $value){

$result[$key] = $this->db->query($value);
}

请帮助:)

2 个答案:

答案 0 :(得分:0)

$id返回的对象不是单个值。尝试插入$id->id_label而不是$id

答案 1 :(得分:0)

获取id_label 试试这个

$id_result = $this->db->query($id_label);
foreach($id_result->result_array() as $row){
     $id=$row['id_label'];
}