我的数据库中有以下表格:
1.寄存器表:
user_id
,用户名
,密码
,电子邮件
,Fname
,Lname
2.Tbl_category:cat_id
3.Tbl_events:
user_id(引用寄存器表)
,cat_id(引用tbl_category)
,event_title
,event_desc
, event_charge
,event_venue
。
在我的模型 event_model 中:
function get_event_details() {
$this -> db -> order_by('event_id', 'desc');
$query = $this -> db -> get('tbl_events');
return $query -> result();
}
在我的 Controller 主页中:
function get_event_details() {
$this -> load -> model('event_model');
$query = $this -> event_model -> get_event_details();
foreach($query as $ca_id):
$c = $ca_id -> cat_id;
endforeach;
if ($c = 1) {
$this -> load -> view('InformationalTechnology');
}
if ($c = 1) {
$this -> load -> view('Entertainment');
}
if ($c = 1) {
$this -> load -> view('Research');
}
if ($c = 1) {
$this -> load -> view('Sports');
}
}
页面即 View 不是基于 $c 显示的。我没有得到应该在哪里更正我的代码的确切点。请建议我最好的方法。
最佳答案
您似乎想根据 cat_id
的值显示特定 View 。但我可以看到您仅将 $c
的值与 1
- 其次,当您的 for 循环在 View 加载之前结束时,您将获得最后一个 cat_id 的 View 。
- 并且您需要使用
==
而不是=
进行比较。
关于mysql - 如何在 View 中显示数据库中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20333866/