foreach 未在视图中显示结果
我的控制器是
<?php
class Blog extends Controller {
function Blog()
{
parent::Controller();
}
function index()
{
$data['title']= "this is a blog";
$data['heading']="Pretty wise";
$data['query']= $this->db->get('entries');
$this->load->view('blogview.php',$data);
}
}
?>
我的视图文件,
<html>
<head>
<title><?= $title ?></title>
</head>
<body>
<h1> <?=$heading?></h1>
<?php foreach($query->result() as $row): ?>
<h3><?= $row->title ?></h3>
<p><?= $row->body ?></p>
<hr>
<?php endforeach; ?>
</body>
</html>
这是一个页面的输出,其中包含这样的内容,
title ?>
body ?>
---------------------
title ?>
body ?>
---------------------
非常错过吧?哈哈,
我确信其他数据库连接的事情, 我正在尝试在数据库中输出两行
my controller is
<?php
class Blog extends Controller {
function Blog()
{
parent::Controller();
}
function index()
{
$data['title']= "this is a blog";
$data['heading']="Pretty wise";
$data['query']= $this->db->get('entries');
$this->load->view('blogview.php',$data);
}
}
?>
my view file is
<html>
<head>
<title><?= $title ?></title>
</head>
<body>
<h1> <?=$heading?></h1>
<?php foreach($query->result() as $row): ?>
<h3><?= $row->title ?></h3>
<p><?= $row->body ?></p>
<hr>
<?php endforeach; ?>
</body>
</html>
the output of this is a page with something like this
title ?>
body ?>
---------------------
title ?>
body ?>
---------------------
pretty missed up huh ? lol
i am sure about other database connectivity stuff,
i am trying to output two rows in my DB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 apache 安装中似乎没有打开短标签。
短标签允许您执行
而不是
It looks like you don't have short tags turned on in your apache install.
Short tags allow you to do
<?= ?>
rather than<?php echo($title); ?>