2016-03-20 14 views
0

Hier ist mein Code in model.phpretrive Daten aus Mysql databse PHP MVC

public function getQuestion($id){ 

$query = mysql_query("select * from bm_question where que_catid = '".$id."'"); 
return $query; 
} 

public function getAnswerforQuestion($qid){ 

$query1 = mysql_query("select * from bm_answer where ans_quid = '".$qid."'"); 
return $query1; 

} 

Und auch unter meiner controller.php

public function index() { 

$this->load->model('quizmodel'); 
$qArr = $this->bm_question->getQustions(que_id); 

foreach ($qArr as $value) {  

//Output Question 
echo $value ->que_question; 

    $this->load->model('quizmodel'); 
$ansArr=$this->answer->getAnswerforQuestion($value ->que_id); 
foreach ($ansArr as $value2) {  
    //output answer 
    echo $value2 ->answer; 

} 
} 

schließlich für diesen Code-I-Fehler unten.

enter image description here

mir helfen, dieses Problem zu lösen. Jede Hilfe kann wirklich geschätzt werden.

Antwort

0

Ich habe nicht getestet, aber es sollte wie unten work.Try: Ihr Modell:

public function getQuestion($id){ 
    $query = $this->db->query("select * from bm_question where que_catid='$id'"); 
    return $query->result(); 
} 

Ihr Modell wie unten in Ihrem Controller laden:

function __construct() 
{ 
    parent::__construct(); 
    $this->load->model('quizmodel'); 
} 

Ihr Controller:

public function index(){ 
$qArr = $this->bm_question->getQuestions($que_id); 
foreach($qArr as $value){ 
    // your code  
    } 
} 
+0

danke @Nagendra. Aber das Ergebnis ist dasselbe. Fehler erscheint für $ qArr = $ this-> bm_question-> getQustions (que_id) Zeile –

+0

@LakshithaGihan Ändern Sie 'bm_question' zu' Bm_question' und es sollte Ihr Modellname sein. Ändern Sie 'getQuestions (que_id)' zu 'getQuestions ($ que_id) '. Du hast' $ 'hier verpasst. – Nagendra

+0

Danke @Nagendra. Dieses Mal wird 'Call to undefined method quizmodel :: getQustion()' auch für diese Zeile angezeigt. –