0

我试图在 CI 中制作 sql 代码,问题是ID_LABEL在 t_publisher 处填充了 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);
}

请帮忙 :)

4

2 回答 2

0

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

于 2012-10-29T04:25:13.750 回答
0

获取 id_label 试试这个

$id_result = $this->db->query($id_label);
foreach($id_result->result_array() as $row){
     $id=$row['id_label'];
}
于 2012-10-29T12:41:40.637 回答