我使用Zend Framework和phpMyAdmin(MySQL)在PHP中创建留言板。我是一个Zend Framework的初学者,并没有在PHP中做过多的工作,所以请尽可能简化您的答案。如何只显示我的数据库中某个表的某些行?
我保存了数据库中留言板的结构(部分,下部分和下部分)。我需要显示论坛的部分及其相应的underSections。问题是 - 我如何显示其下的特定部分的底部部分?
IndexController.php
:
public function indexAction()
{
$sections = new Model_Sections();
$this->view->sections = $sections->fetchAll();
$undersections = new Model_Undersections();
$this->view->undersections = $undersections->fetchAll();
}
在这段代码中我获取所有部分和undersection数据(ID &名)。
数据库模型Section.php
:
class Model_Sections extends Zend_Db_Table_Abstract
{
protected $_name = 'sections';
}
数据库模型Undersection.php
:
<div class="section">
<?php foreach($this->sections as $sections) : ?>
<!-- Generates names of sections -->
<h1><?php echo $this->escape($sections->section_name);?></h1>
<!-- Generates names of undersections -->
<?php foreach($this->undersections as $undersections) : ?>
<div class="underSection">
<h2>
<a href=" ***link to some controller according to the undersection*** ">
<?php echo $this->escape($undersections->undersection_name);?>
</a>
</h2>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
目前它:从有关数据输出的主视图 “index.phtml”
class Model_Undersections extends Zend_Db_Table_Abstract
{
protected $_name = 'undersections';
}
片段显示每个部分下的所有低点。
什么是你的数据库结构?您目前没有任何将部分与底标联系在一起的部分 –
部分表具有主键“section_id”,它是底部表中的外键。 – ositra