0
pertanyaan_1 난이 기능을 가지고 :메시지 : 정의되지 않은 인덱스 :
public function populateAtribut()
{
$this->db->query("TRUNCATE atribut");
$this->db->query("insert into `atribut` values
('', 'Total', 'Total')
");
$this->insertAtribut('pertanyaan_1');
$this->insertAtribut('pertanyaan_2');
$this->insertAtribut('pertanyaan_3');
$this->insertAtribut('pertanyaan_4');
$this->insertAtribut('pertanyaan_5');
$this->insertAtribut('pertanyaan_6');
$this->insertAtribut('pertanyaan_7');
$this->insertAtribut('pertanyaan_8');
$this->insertAtribut('pertanyaan_9');
$this->insertAtribut('pertanyaan_10');
$this->insertAtribut('pertanyaan_11');
$this->insertAtribut('pertanyaan_12');
$this->insertAtribut('pertanyaan_13');
$this->insertAtribut('pertanyaan_14');
$this->insertAtribut('pertanyaan_15');
$this->insertAtribut('pertanyaan_16');
$this->insertAtribut('pertanyaan_17');
$this->insertAtribut('pertanyaan_18');
$this->insertAtribut('pertanyaan_19');
$this->insertAtribut('pertanyaan_20');
}
을하고 난 다음과 같은 기능 insertAtribut
을 가지고 :
public function insertAtribut($atribut) {
$sqlAtribut = $this->db->query("SELECT distinct `$atribut` FROM data_kepribadian ORDER by `$atribut`");
while ($rowAtribut = $sqlAtribut->result_array()) {!
$this->db->query("insert into `atribut` values
('', '$atribut', '$rowAtribut[$atribut]')");
}
}
하지만 난 오류가있어 :
Message: Undefined index: pertanyaan_1
과를 프로그램은 데이터베이스에 멈추지 않고 데이터를 삽입합니다.
어떻게 수정합니까? 루프 조건부 동안
당신은이 오류를 얻고있다 인덱스'pertanyaan_1 때문에 '이'$ rowAtribut [$ atribut]'데이터베이스 테이블'data_kepribadian'에는 존재하지 않습니다. – Alex
함수 insertAtribut에서 $ atribut의 값이 유효하고 테이블 data_kepribadian에 포함되어 있다는 것을 당연한 것으로 간주합니다. 그렇지 않은 경우 어떻게됩니까? 테이블의 데이터를 검증하십시오. 그리고 오류 시나리오를 처리하여 기능을 더욱 강력하게 만드십시오. – Nic3500
tabel_ @prepribadian의 @Alex 필드에 pertanyaan_1이 있습니다. –