我试图在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);
}
请帮助:)
答案 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'];
}