gpt4 book ai didi

php - 从 Mysql 数据库检索数据 PHP MVC

转载 作者:行者123 更新时间:2023-11-29 21:14:02 24 4
gpt4 key购买 nike

这是我在 model.php 中的代码

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;

}

下面是我的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;
}
}

最后我发现这段代码出错了。

enter image description here

最佳答案

我还没有测试过,但它应该可以工作。尝试如下:您的型号:

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

将模型加载到 Controller 中,如下所示:

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

您的 Controller :

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

关于php - 从 Mysql 数据库检索数据 PHP MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36113320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com