Codeigniter 从数据库填充表
我想使用 但我无法让它工作。请检查我的代码:
controller
$data['query'] = $this->db->query('SELECT * FROM users');
$this->load->view('users_view',$data);
View
<?php foreach ($query->result_array() as $row)
{ ;?>
<tr>
<td><?php echo $row['usrID'];?></td>
<td><?php echo $row['usrName'];?></td>
<td><?php echo $row['usrPassword'];?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
I want to populate all the data from my database to a table using <?php foreach; ?>
but I can't get it to work. Please check my code:
controller
$data['query'] = $this->db->query('SELECT * FROM users');
$this->load->view('users_view',$data);
View
<?php foreach ($query->result_array() as $row)
{ ;?>
<tr>
<td><?php echo $row['usrID'];?></td>
<td><?php echo $row['usrName'];?></td>
<td><?php echo $row['usrPassword'];?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会推荐视图中 foreach 的替代语法...
看起来您应该有一些语法错误。
编辑 - 指出您的语法问题。
第一个分号就像编写这样的 foreach...
除了问题点之外的意见
您应该在控制器中处理数据并简单地发送一个数组要在视图中显示的数据,而不是整个查询对象。
所以...
控制器
I would reccommend the alternative syntax for your foreach in the view...
It looks like you should be having some syntax errors the way you have it.
EDIT - to point out your syntax issues.
This first semicolon would be like writing a foreach like this...
Opinion aside from the point of the question
You should be processing your data in the controller and simply sending an array of data to be displayed in the view, not the whole query object.
so...
Controller