2012-10-29 86 views
0

我試圖使SQL代碼CI,問題是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); 
} 

請幫助:)

回答

0

$id返回一個對象不是一個單一的值。嘗試插入$id->id_label,而不是僅僅$id

+0

我應該在哪裏寫$ ID-> id_label? – user1781895

+0

在query3中,您將$ id作爲值插入。 –

+0

$ sql ['query3'] =「INSERT INTO t_publisher(PUBLISHER,ARTIS,ID_LABEL)values('$ user','Various Artist','$ id-> id_label')」; 那樣?我會嘗試..但是,它仍然在數據庫上:( – user1781895

0

得到id_label 試試這個

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

我應該在哪裏放這段代碼? – user1781895