gpt4 book ai didi

php - 提供的参数无效 Codeigniter

转载 作者:行者123 更新时间:2023-11-29 19:08:50 25 4
gpt4 key购买 nike

我的程序无法正常工作,我不知道该怎么办:S

我收到此错误消息: enter image description here

看看这个: enter image description here

这是我的代码:我的 Controller 文件(主页):

    <?php

class Home extends CI_Controller{

public function __construct(){
parent::__construct();

$this->load->model("Crudmodel");

}


public function index(){

# get all data in Study table
$selectStudys = $this->Crudmodel->selectStudys();


foreach ($selectStudys as $key => $study)
{
# get UserNames
$user = $this->Crudmodel->getName($study['user_id']);

#get Subject Names
$subject = $this->Crudmodel->getSubName($study['subject_id']);


#append both NEW VALUES to same array

if(!empty($user[0]['username'])){
$data[$key]['user_id'] = $user[0]['username'];
// your main problem can be this. may be it is not getting value from query this is why we have put validation on model function and error handler condition here
}else{
$data[$key]['user_id'] = ''; // or anything as your else condition you can use as error handler
}
if(!empty($subject[0]['name'])){
$data[$key]['subject_id'] = $subject[0]['name'];
// your main problem can be this. may be it is not getting value from query this is why we have put validation on model function and error handler condition here
}else{
$data[$key]["subject_id"] = "";
// or anything you can use as error handler
}

}


$data['records'] = $selectStudys;
$this->load->view('home', $data);

}

}
?>

粗略模型:

       class Crudmodel extends CI_Model{

public function __construct(){
parent::__construct();

$this->load->database();

}


function selectStudys()
{
$query= $this->db->query("SELECT * FROM cursadas");
if($query->num_rows()>0){
$result = $query->result_array();
}else{
$result = "";
// or anything you can use as error handler
return $result;
}
}

function getName($name)
{
$query= $this->db->query("SELECT username FROM usuarios WHERE id = $name ");
if($query->num_rows()>0){
$result = $query->result_array();
}else{
$result = "";
// or anything you can use as error handler
return $result;
}
}

现在不知道该怎么办:(

希望你能帮助我:S

最佳答案

问题出在模型上。您只返回 else 内的内容。修复很简单,移动return即可。

如果没有行,您可能应该返回一个空数组。那么 foreach 仍然会有一些东西可以使用 - 即使它是空的。如果给定一些不能在循环中使用的东西(例如字符串),foreach 将会阻塞。

function selectStudys()
{
$query= $this->db->query("SELECT * FROM cursadas");
if($query->num_rows()>0){
$result = $query->result_array();
}else{
$result = array();
}
return $result;
}

关于php - 提供的参数无效 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43258878/

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