Php foreach传递变量和查询中的codeigniter错误
我试图用数据库表中的事件数组填充下拉表单 我遇到了各种各样的错误: 未定义的$user\u事件 等等 我知道这是我从控制器传递数组的方式 型号:Php foreach传递变量和查询中的codeigniter错误,php,codeigniter,Php,Codeigniter,我试图用数据库表中的事件数组填充下拉表单 我遇到了各种各样的错误: 未定义的$user\u事件 等等 我知道这是我从控制器传递数组的方式 型号: public function dropdown_add_event($id, $Id) { $sql = "SELECT * FROM table_eventcards WHERE table_eventcards.id = ? AND table_event
public function dropdown_add_event($id, $Id)
{
$sql = "SELECT *
FROM table_eventcards
WHERE table_eventcards.id = ?
AND table_eventcards.Id = ?";
$query = $this->db->query($sql, array($id, $Id));
return $query->result_array();
}
控制器:
$this->data['user_events'] = $this->model_location->dropdown_add_event(); // Retrieve an array of user events
$fkUserId = $data['fkUserId'];
$this->data['user_events'] = $this->model_location->dropdown_add_event($id, $fkUserId);
$this->load->view('view_name', $this->data);
视图:
在控制器中,您似乎忘记给出参数:
$this->data['user_events'] = $this->model_location->dropdown_add_event();
// ^^ $id, $fkUserId
未传递/找到任何参数下拉菜单添加事件()代码>
只需传递控制器上的适当变量:
$this->data['user_events'] = $this->model_location->dropdown_add_event(); // Retrieve an array of user events
$fkUserId = $data['fkUserId'];
$this->data['user_events'] = $this->model_location->dropdown_add_event($id, $fkUserId);
$this->load->view('view_name', $this->data);
您不应该在这里传递一些参数吗$this->model_location->dropdown_add_event()代码>?哎呀,这是个简单的错误,谢谢,但现在它说的是未定义变量$id和未定义变量$fkUserId。我在哪里定义它们?@Bobby你是什么意思?(那些变量)不是在你的控制器中吗?在我文章的底部。@Bobby哦,好的,我假设你已经得到了你的$id
对吗?检查我的修改可能是因为我累了,但我想我正在抓取查询中的TACTIFY_eventcards.id的id。我不知道应该如何设置$id,因为我没有看到。我正在处理别人的代码。